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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Analysis;
|
---|
26 | using HeuristicLab.Core.Views;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 | using RegressionType = HeuristicLab.Analysis.ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
31 |
|
---|
32 | [View("Scatter Plot Single View")]
|
---|
33 | [Content(typeof(SingleScatterPlotContent), true)]
|
---|
34 | public partial class ScatterPlotSingleView : ItemView {
|
---|
35 |
|
---|
36 | public new SingleScatterPlotContent Content {
|
---|
37 | get { return (SingleScatterPlotContent)base.Content; }
|
---|
38 | set { base.Content = value; }
|
---|
39 | }
|
---|
40 |
|
---|
41 | public ScatterPlotSingleView() {
|
---|
42 | InitializeComponent();
|
---|
43 |
|
---|
44 | regressionTypeComboBox.DataSource = Enum.GetValues(typeof(RegressionType));
|
---|
45 | regressionTypeComboBox.SelectedItem = RegressionType.None;
|
---|
46 | }
|
---|
47 |
|
---|
48 | public void InitData() {
|
---|
49 | IEnumerable<string> variables = Content.PreprocessingData.GetDoubleVariableNames();
|
---|
50 |
|
---|
51 | // add variables to combo boxes
|
---|
52 | comboBoxXVariable.Items.Clear();
|
---|
53 | comboBoxYVariable.Items.Clear();
|
---|
54 | comboBoxGroup.Items.Clear();
|
---|
55 | comboBoxXVariable.Items.AddRange(variables.ToArray());
|
---|
56 | comboBoxYVariable.Items.AddRange(variables.ToArray());
|
---|
57 | comboBoxGroup.Items.Add("-");
|
---|
58 | for (int i = 0; i < Content.PreprocessingData.Columns; ++i) {
|
---|
59 | if (Content.PreprocessingData.VariableHasType<double>(i)) {
|
---|
60 | double distinctValueCount = Content.PreprocessingData.GetValues<double>(i).GroupBy(x => x).Count();
|
---|
61 | if (distinctValueCount <= 20)
|
---|
62 | comboBoxGroup.Items.Add(Content.PreprocessingData.GetVariableName(i));
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | // use x and y variable from content
|
---|
67 | if (Content.SelectedXVariable != null && Content.SelectedYVariable != null && Content.SelectedGroupVariable != null) {
|
---|
68 | comboBoxXVariable.SelectedItem = Content.SelectedXVariable;
|
---|
69 | comboBoxYVariable.SelectedItem = Content.SelectedYVariable;
|
---|
70 | comboBoxGroup.SelectedItem = Content.SelectedGroupVariable;
|
---|
71 | } else {
|
---|
72 | if (variables.Count() >= 2) {
|
---|
73 | comboBoxXVariable.SelectedIndex = 0;
|
---|
74 | comboBoxYVariable.SelectedIndex = 1;
|
---|
75 | comboBoxGroup.SelectedIndex = 0;
|
---|
76 | UpdateScatterPlot();
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | protected override void OnContentChanged() {
|
---|
82 | base.OnContentChanged();
|
---|
83 | if (Content != null) {
|
---|
84 | InitData();
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | private void UpdateScatterPlot() {
|
---|
89 | if (comboBoxXVariable.SelectedItem != null && comboBoxYVariable.SelectedItem != null && comboBoxGroup.SelectedItem != null) {
|
---|
90 | var xVariable = (string)comboBoxXVariable.SelectedItem;
|
---|
91 | var yVariable = (string)comboBoxYVariable.SelectedItem;
|
---|
92 | var groupVariable = (string)comboBoxGroup.SelectedItem;
|
---|
93 | ScatterPlot scatterPlot = Content.CreateScatterPlot(xVariable, yVariable, groupVariable);
|
---|
94 | var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
|
---|
95 | int order = (int)polynomialRegressionOrderNumericUpDown.Value;
|
---|
96 | foreach (var row in scatterPlot.Rows) {
|
---|
97 | row.VisualProperties.PointSize = 6;
|
---|
98 | row.VisualProperties.IsRegressionVisibleInLegend = false;
|
---|
99 | row.VisualProperties.RegressionType = regressionType;
|
---|
100 | row.VisualProperties.PolynomialRegressionOrder = order;
|
---|
101 | }
|
---|
102 | var vp = scatterPlot.VisualProperties;
|
---|
103 | vp.Title = string.Empty;
|
---|
104 | vp.XAxisTitle = xVariable;
|
---|
105 | vp.YAxisTitle = yVariable;
|
---|
106 |
|
---|
107 | scatterPlotControl.Content = scatterPlot;
|
---|
108 |
|
---|
109 | //save selected x and y variable in content
|
---|
110 | this.Content.SelectedXVariable = (string)comboBoxXVariable.SelectedItem;
|
---|
111 | this.Content.SelectedYVariable = (string)comboBoxYVariable.SelectedItem;
|
---|
112 | this.Content.SelectedGroupVariable = (string)comboBoxGroup.SelectedItem;
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | private void comboBoxXVariable_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
117 | var oldPlot = scatterPlotControl.Content;
|
---|
118 | UpdateScatterPlot();
|
---|
119 | var newPlot = scatterPlotControl.Content;
|
---|
120 |
|
---|
121 |
|
---|
122 | if (oldPlot == null || newPlot == null) return;
|
---|
123 | newPlot.VisualProperties.YAxisMinimumAuto = oldPlot.VisualProperties.YAxisMinimumAuto;
|
---|
124 | newPlot.VisualProperties.YAxisMaximumAuto = oldPlot.VisualProperties.YAxisMaximumAuto;
|
---|
125 | newPlot.VisualProperties.YAxisMinimumFixedValue = oldPlot.VisualProperties.YAxisMinimumFixedValue;
|
---|
126 | newPlot.VisualProperties.YAxisMaximumFixedValue = oldPlot.VisualProperties.YAxisMaximumFixedValue;
|
---|
127 |
|
---|
128 | foreach (var x in newPlot.Rows.Zip(oldPlot.Rows, (nr, or) => new { nr, or })) {
|
---|
129 | var newVisuapProperties = (ScatterPlotDataRowVisualProperties)x.or.VisualProperties.Clone();
|
---|
130 | newVisuapProperties.DisplayName = x.nr.VisualProperties.DisplayName;
|
---|
131 | x.nr.VisualProperties = newVisuapProperties;
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | private void comboBoxYVariable_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
136 | var oldPlot = scatterPlotControl.Content;
|
---|
137 | UpdateScatterPlot();
|
---|
138 | var newPlot = scatterPlotControl.Content;
|
---|
139 |
|
---|
140 | if (oldPlot == null || newPlot == null) return;
|
---|
141 | newPlot.VisualProperties.XAxisMinimumAuto = oldPlot.VisualProperties.XAxisMinimumAuto;
|
---|
142 | newPlot.VisualProperties.XAxisMaximumAuto = oldPlot.VisualProperties.XAxisMaximumAuto;
|
---|
143 | newPlot.VisualProperties.XAxisMinimumFixedValue = oldPlot.VisualProperties.XAxisMinimumFixedValue;
|
---|
144 | newPlot.VisualProperties.XAxisMaximumFixedValue = oldPlot.VisualProperties.XAxisMaximumFixedValue;
|
---|
145 |
|
---|
146 | foreach (var x in newPlot.Rows.Zip(oldPlot.Rows, (nr, or) => new { nr, or })) {
|
---|
147 | var newVisuapProperties = (ScatterPlotDataRowVisualProperties)x.or.VisualProperties.Clone();
|
---|
148 | newVisuapProperties.DisplayName = x.nr.VisualProperties.DisplayName;
|
---|
149 | x.nr.VisualProperties = newVisuapProperties;
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 | private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
154 | UpdateScatterPlot();
|
---|
155 | }
|
---|
156 |
|
---|
157 | #region Regression Line
|
---|
158 | private void regressionTypeComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
159 | var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
|
---|
160 | polynomialRegressionOrderNumericUpDown.Enabled = regressionType == RegressionType.Polynomial;
|
---|
161 | UpdateRegressionLine();
|
---|
162 | }
|
---|
163 |
|
---|
164 | private void polynomialRegressionOrderNumericUpDown_ValueChanged(object sender, EventArgs e) {
|
---|
165 | UpdateRegressionLine();
|
---|
166 | }
|
---|
167 |
|
---|
168 | private void UpdateRegressionLine() {
|
---|
169 | var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
|
---|
170 | int order = (int)polynomialRegressionOrderNumericUpDown.Value;
|
---|
171 |
|
---|
172 | foreach (var row in scatterPlotControl.Content.Rows) {
|
---|
173 | row.VisualProperties.IsRegressionVisibleInLegend = false;
|
---|
174 | row.VisualProperties.RegressionType = regressionType;
|
---|
175 | row.VisualProperties.PolynomialRegressionOrder = order;
|
---|
176 | }
|
---|
177 | }
|
---|
178 | #endregion
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|