[13502] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[13502] | 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;
|
---|
[10882] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Analysis;
|
---|
| 26 | using HeuristicLab.Core.Views;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
| 30 |
|
---|
[10987] | 31 | [View("Scatter Plot Single View")]
|
---|
[14467] | 32 | [Content(typeof(SingleScatterPlotContent), true)]
|
---|
[10987] | 33 | public partial class ScatterPlotSingleView : ItemView {
|
---|
[10882] | 34 |
|
---|
[14467] | 35 | public new SingleScatterPlotContent Content {
|
---|
| 36 | get { return (SingleScatterPlotContent)base.Content; }
|
---|
[10882] | 37 | set { base.Content = value; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[13502] | 40 | public ScatterPlotSingleView() {
|
---|
[10998] | 41 | InitializeComponent();
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[10882] | 44 | public void InitData() {
|
---|
[10992] | 45 | IEnumerable<string> variables = Content.PreprocessingData.GetDoubleVariableNames();
|
---|
[10972] | 46 |
|
---|
| 47 | // add variables to combo boxes
|
---|
[10882] | 48 | comboBoxXVariable.Items.Clear();
|
---|
| 49 | comboBoxYVariable.Items.Clear();
|
---|
[14467] | 50 | comboBoxGroup.Items.Clear();
|
---|
[10882] | 51 | comboBoxXVariable.Items.AddRange(variables.ToArray());
|
---|
| 52 | comboBoxYVariable.Items.AddRange(variables.ToArray());
|
---|
[14467] | 53 | comboBoxGroup.Items.Add("-");
|
---|
[13502] | 54 | for (int i = 0; i < Content.PreprocessingData.Columns; ++i) {
|
---|
| 55 | if (Content.PreprocessingData.VariableHasType<double>(i)) {
|
---|
| 56 | double distinctValueCount = Content.PreprocessingData.GetValues<double>(i).GroupBy(x => x).Count();
|
---|
| 57 | if (distinctValueCount <= 20)
|
---|
[14467] | 58 | comboBoxGroup.Items.Add(Content.PreprocessingData.GetVariableName(i));
|
---|
[13502] | 59 | }
|
---|
| 60 | }
|
---|
[10882] | 61 |
|
---|
[10952] | 62 | // use x and y variable from content
|
---|
[14467] | 63 | if (Content.SelectedXVariable != null && Content.SelectedYVariable != null && Content.SelectedGroupVariable != null) {
|
---|
[10952] | 64 | comboBoxXVariable.SelectedItem = Content.SelectedXVariable;
|
---|
| 65 | comboBoxYVariable.SelectedItem = Content.SelectedYVariable;
|
---|
[14467] | 66 | comboBoxGroup.SelectedItem = Content.SelectedGroupVariable;
|
---|
[10952] | 67 | } else {
|
---|
| 68 | if (variables.Count() >= 2) {
|
---|
| 69 | comboBoxXVariable.SelectedIndex = 0;
|
---|
| 70 | comboBoxYVariable.SelectedIndex = 1;
|
---|
[14467] | 71 | comboBoxGroup.SelectedIndex = 0;
|
---|
[10952] | 72 | UpdateScatterPlot();
|
---|
| 73 | }
|
---|
[10882] | 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | protected override void OnContentChanged() {
|
---|
| 78 | base.OnContentChanged();
|
---|
| 79 | if (Content != null) {
|
---|
| 80 | InitData();
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | private void UpdateScatterPlot() {
|
---|
[14467] | 85 | if (comboBoxXVariable.SelectedItem != null && comboBoxYVariable.SelectedItem != null && comboBoxGroup.SelectedItem != null) {
|
---|
[14446] | 86 | var xVariable = (string)comboBoxXVariable.SelectedItem;
|
---|
| 87 | var yVariable = (string)comboBoxYVariable.SelectedItem;
|
---|
[14467] | 88 | var groupVariable = (string)comboBoxGroup.SelectedItem;
|
---|
| 89 | ScatterPlot scatterPlot = Content.CreateScatterPlot(xVariable, yVariable, groupVariable);
|
---|
[14446] | 90 | var vp = scatterPlot.VisualProperties;
|
---|
| 91 | vp.Title = string.Empty;
|
---|
| 92 | vp.XAxisTitle = xVariable;
|
---|
| 93 | vp.YAxisTitle = yVariable;
|
---|
[10952] | 94 |
|
---|
[14446] | 95 | scatterPlotControl.Content = scatterPlot;
|
---|
[14467] | 96 |
|
---|
[10952] | 97 | //save selected x and y variable in content
|
---|
| 98 | this.Content.SelectedXVariable = (string)comboBoxXVariable.SelectedItem;
|
---|
| 99 | this.Content.SelectedYVariable = (string)comboBoxYVariable.SelectedItem;
|
---|
[14467] | 100 | this.Content.SelectedGroupVariable = (string)comboBoxGroup.SelectedItem;
|
---|
[10882] | 101 | }
|
---|
| 102 | }
|
---|
[14470] | 103 |
|
---|
| 104 | private void comboBoxXVariable_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 105 | var oldPlot = scatterPlotControl.Content;
|
---|
| 106 | UpdateScatterPlot();
|
---|
| 107 | var newPlot = scatterPlotControl.Content;
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | if (oldPlot == null || newPlot == null) return;
|
---|
| 111 | newPlot.VisualProperties.YAxisMinimumAuto = oldPlot.VisualProperties.YAxisMinimumAuto;
|
---|
| 112 | newPlot.VisualProperties.YAxisMaximumAuto = oldPlot.VisualProperties.YAxisMaximumAuto;
|
---|
| 113 | newPlot.VisualProperties.YAxisMinimumFixedValue = oldPlot.VisualProperties.YAxisMinimumFixedValue;
|
---|
| 114 | newPlot.VisualProperties.YAxisMaximumFixedValue = oldPlot.VisualProperties.YAxisMaximumFixedValue;
|
---|
| 115 |
|
---|
| 116 | foreach (var x in newPlot.Rows.Zip(oldPlot.Rows, (nr, or) => new { nr, or })) {
|
---|
| 117 | x.nr.VisualProperties.PointSize = x.or.VisualProperties.PointSize;
|
---|
| 118 | x.nr.VisualProperties.PointStyle = x.or.VisualProperties.PointStyle;
|
---|
| 119 | x.nr.VisualProperties.Color = x.or.VisualProperties.Color;
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | private void comboBoxYVariable_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 124 | var oldPlot = scatterPlotControl.Content;
|
---|
| 125 | UpdateScatterPlot();
|
---|
| 126 | var newPlot = scatterPlotControl.Content;
|
---|
| 127 |
|
---|
| 128 | if (oldPlot == null || newPlot == null) return;
|
---|
| 129 | newPlot.VisualProperties.XAxisMinimumAuto = oldPlot.VisualProperties.XAxisMinimumAuto;
|
---|
| 130 | newPlot.VisualProperties.XAxisMaximumAuto = oldPlot.VisualProperties.XAxisMaximumAuto;
|
---|
| 131 | newPlot.VisualProperties.XAxisMinimumFixedValue = oldPlot.VisualProperties.XAxisMinimumFixedValue;
|
---|
| 132 | newPlot.VisualProperties.XAxisMaximumFixedValue = oldPlot.VisualProperties.XAxisMaximumFixedValue;
|
---|
| 133 |
|
---|
| 134 | foreach (var x in newPlot.Rows.Zip(oldPlot.Rows, (nr, or) => new { nr, or })) {
|
---|
| 135 | x.nr.VisualProperties.PointSize = x.or.VisualProperties.PointSize;
|
---|
| 136 | x.nr.VisualProperties.PointStyle = x.or.VisualProperties.PointStyle;
|
---|
| 137 | x.nr.VisualProperties.Color = x.or.VisualProperties.Color;
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 142 | UpdateScatterPlot();
|
---|
| 143 | }
|
---|
[10882] | 144 | }
|
---|
| 145 | }
|
---|