Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Analysis.Views/3.3/ScatterPlotDataRowVisualPropertiesControl.cs @ 14648

Last change on this file since 14648 was 14493, checked in by pfleck, 8 years ago

#2713 Added option in the ScatterPlotControl to show a regression curve for a ScatterPlotDataRow (linear, poly, exp, log, pow).

File size: 6.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Drawing;
24using System.Windows.Forms;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27
28namespace HeuristicLab.Analysis.Views {
29  [View("ScatterPlot DataRow Visual Properties")]
30  public partial class ScatterPlotDataRowVisualPropertiesControl : UserControl {
31    protected bool SuppressEvents { get; set; }
32
33    private ScatterPlotDataRowVisualProperties content;
34    public ScatterPlotDataRowVisualProperties Content {
35      get { return content; }
36      set {
37        bool changed = (value != content);
38        content = value;
39        if (changed) OnContentChanged();
40      }
41    }
42
43    public ScatterPlotDataRowVisualPropertiesControl() {
44      InitializeComponent();
45      pointStyleComboBox.DataSource = Enum.GetValues(typeof(ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle));
46      regressionTypeComboBox.DataSource = Enum.GetValues(typeof(ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType));
47      SetEnabledStateOfControls();
48    }
49
50    protected virtual void OnContentChanged() {
51      SuppressEvents = true;
52      try {
53        if (Content == null) {
54          pointStyleComboBox.SelectedIndex = -1;
55          colorButton.BackColor = SystemColors.Control;
56          colorButton.Text = "?";
57          isVisibleInLegendCheckBox.Checked = false;
58          pointSizeNumericUpDown.Value = 1;
59          displayNameTextBox.Text = String.Empty;
60          regressionTypeComboBox.SelectedIndex = -1;
61          polynomialRegressionOrderNumericUpDown.Value = 2;
62          isRegressionVisibleInLegendCheckBox.Checked = false;
63          regressionLegendTextBox.Text = string.Empty;
64        } else {
65          displayNameTextBox.Text = Content.DisplayName;
66          pointStyleComboBox.SelectedItem = Content.PointStyle;
67          if (Content.Color.IsEmpty) {
68            colorButton.BackColor = SystemColors.Control;
69            colorButton.Text = "?";
70          } else {
71            colorButton.BackColor = Content.Color;
72            colorButton.Text = String.Empty;
73          }
74          pointSizeNumericUpDown.Value = Content.PointSize;
75          isVisibleInLegendCheckBox.Checked = Content.IsVisibleInLegend;
76          regressionTypeComboBox.SelectedItem = Content.RegressionType;
77          polynomialRegressionOrderNumericUpDown.Value = Content.PolynomialRegressionOrder;
78          isRegressionVisibleInLegendCheckBox.Checked = Content.IsRegressionVisibleInLegend;
79          regressionLegendTextBox.Text = content.RegressionDisplayName;
80        }
81      }
82      finally { SuppressEvents = false; }
83      SetEnabledStateOfControls();
84    }
85
86    protected virtual void SetEnabledStateOfControls() {
87      pointStyleComboBox.Enabled = Content != null;
88      colorButton.Enabled = Content != null;
89      colorButton.Enabled = Content != null;
90      isVisibleInLegendCheckBox.Enabled = Content != null;
91      pointSizeNumericUpDown.Enabled = Content != null;
92      displayNameTextBox.Enabled = Content != null;
93      regressionTypeComboBox.Enabled = Content != null;
94      polynomialRegressionOrderNumericUpDown.Enabled = Content != null && Content.RegressionType == ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType.Polynomial;
95      orderLabel.Enabled = polynomialRegressionOrderNumericUpDown.Enabled;
96      isRegressionVisibleInLegendCheckBox.Enabled = Content != null && Content.RegressionType != ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType.None;
97      regressionLegendTextBox.Enabled = Content != null && Content.RegressionType != ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType.None;
98    }
99
100    #region Event Handlers
101    private void pointStyleComboBox_SelectedValueChanged(object sender, EventArgs e) {
102      if (!SuppressEvents && Content != null) {
103        var selected = (ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle)pointStyleComboBox.SelectedValue;
104        Content.PointStyle = selected;
105      }
106    }
107
108    private void colorButton_Click(object sender, EventArgs e) {
109      if (colorDialog.ShowDialog() == DialogResult.OK) {
110        Content.Color = colorDialog.Color;
111        colorButton.BackColor = Content.Color;
112        colorButton.Text = String.Empty;
113      }
114    }
115
116    private void displayNameTextBox_Validated(object sender, EventArgs e) {
117      if (!SuppressEvents && Content != null) {
118        SuppressEvents = true;
119        try {
120          Content.DisplayName = displayNameTextBox.Text;
121        }
122        finally { SuppressEvents = false; }
123      }
124    }
125
126    private void pointSizeNumericUpDown_ValueChanged(object sender, EventArgs e) {
127      if (!SuppressEvents && Content != null) {
128        Content.PointSize = (int)pointSizeNumericUpDown.Value;
129      }
130    }
131
132    private void isVisibleInLegendCheckBox_CheckedChanged(object sender, EventArgs e) {
133      if (!SuppressEvents && Content != null) {
134        Content.IsVisibleInLegend = isVisibleInLegendCheckBox.Checked;
135      }
136    }
137
138    private void regressionTypeComboBox_SelectedValueChanged(object sender, EventArgs e) {
139      if (!SuppressEvents && Content != null) {
140        var selected = (ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType)regressionTypeComboBox.SelectedValue;
141        Content.RegressionType = selected;
142        SetEnabledStateOfControls();
143      }
144    }
145
146    private void polynomialRegressionOrderNumericUpDown_ValueChanged(object sender, EventArgs e) {
147      if (!SuppressEvents && Content != null) {
148        Content.PolynomialRegressionOrder = (int)polynomialRegressionOrderNumericUpDown.Value;
149      }
150    }
151
152    private void isRegressionVisibleInLegendCheckBox_CheckedChanged(object sender, EventArgs e) {
153      if (!SuppressEvents && Content != null) {
154        Content.IsRegressionVisibleInLegend = isRegressionVisibleInLegendCheckBox.Checked;
155      }
156    }
157
158    private void regressionLegendTextBox_Validated(object sender, EventArgs e) {
159      if (!SuppressEvents && Content != null) {
160        Content.RegressionDisplayName = regressionLegendTextBox.Text;
161      }
162    }
163    #endregion
164  }
165}
Note: See TracBrowser for help on using the repository browser.