Changeset 14521 for branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4
- Timestamp:
- 12/22/16 12:42:09 (8 years ago)
- Location:
- branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/HeuristicLab.DataPreprocessing.Views-3.4.csproj
r14514 r14521 317 317 <Name>HeuristicLab.DataPreprocessing-3.4</Name> 318 318 </ProjectReference> 319 </ItemGroup> 320 <ItemGroup> 321 <EmbeddedResource Include="ScatterPlotSingleView.resx"> 322 <DependentUpon>ScatterPlotSingleView.cs</DependentUpon> 323 </EmbeddedResource> 319 324 </ItemGroup> 320 325 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotSingleView.Designer.cs
r14514 r14521 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ScatterPlotSingleView)); 47 48 this.scatterPlotControl = new HeuristicLab.Analysis.Views.ScatterPlotControl(); 48 49 this.groupBox1 = new System.Windows.Forms.GroupBox(); 50 this.useGradientCheckBox = new System.Windows.Forms.CheckBox(); 49 51 this.label3 = new System.Windows.Forms.Label(); 50 52 this.label2 = new System.Windows.Forms.Label(); … … 59 61 this.label4 = new System.Windows.Forms.Label(); 60 62 this.splitContainer1 = new System.Windows.Forms.SplitContainer(); 63 this.gradientPanel = new System.Windows.Forms.Panel(); 64 this.gradientMinimumLabel = new System.Windows.Forms.Label(); 65 this.gradientMaximumLabel = new System.Windows.Forms.Label(); 66 this.gradientPictureBox = new System.Windows.Forms.PictureBox(); 61 67 this.groupBox1.SuspendLayout(); 62 68 this.regressionGroupBox.SuspendLayout(); … … 66 72 this.splitContainer1.Panel2.SuspendLayout(); 67 73 this.splitContainer1.SuspendLayout(); 74 this.gradientPanel.SuspendLayout(); 75 ((System.ComponentModel.ISupportInitialize)(this.gradientPictureBox)).BeginInit(); 68 76 this.SuspendLayout(); 69 77 // 70 78 // scatterPlotControl 71 79 // 80 this.scatterPlotControl.Caption = "View"; 72 81 this.scatterPlotControl.Content = null; 73 82 this.scatterPlotControl.Dock = System.Windows.Forms.DockStyle.Fill; 74 83 this.scatterPlotControl.Location = new System.Drawing.Point(0, 0); 75 84 this.scatterPlotControl.Name = "scatterPlotControl"; 76 this.scatterPlotControl.Size = new System.Drawing.Size(687, 517); 85 this.scatterPlotControl.ReadOnly = false; 86 this.scatterPlotControl.Size = new System.Drawing.Size(618, 517); 77 87 this.scatterPlotControl.TabIndex = 0; 78 88 // 79 89 // groupBox1 80 90 // 91 this.groupBox1.Controls.Add(this.useGradientCheckBox); 81 92 this.groupBox1.Controls.Add(this.label3); 82 93 this.groupBox1.Controls.Add(this.label2); … … 88 99 this.groupBox1.Location = new System.Drawing.Point(0, 0); 89 100 this.groupBox1.Name = "groupBox1"; 90 this.groupBox1.Size = new System.Drawing.Size(172, 1 37);101 this.groupBox1.Size = new System.Drawing.Size(172, 150); 91 102 this.groupBox1.TabIndex = 1; 92 103 this.groupBox1.TabStop = false; 93 104 this.groupBox1.Text = "Variables"; 105 // 106 // useGradientCheckBox 107 // 108 this.useGradientCheckBox.AutoSize = true; 109 this.useGradientCheckBox.Location = new System.Drawing.Point(51, 121); 110 this.useGradientCheckBox.Name = "useGradientCheckBox"; 111 this.useGradientCheckBox.Size = new System.Drawing.Size(115, 17); 112 this.useGradientCheckBox.TabIndex = 4; 113 this.useGradientCheckBox.Text = "Use Color Gradient"; 114 this.useGradientCheckBox.UseVisualStyleBackColor = true; 115 this.useGradientCheckBox.CheckedChanged += new System.EventHandler(this.useGradientCheckBox_CheckedChanged); 94 116 // 95 117 // label3 … … 122 144 // comboBoxGroup 123 145 // 124 this.comboBoxGroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 146 this.comboBoxGroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 125 147 | System.Windows.Forms.AnchorStyles.Right))); 126 148 this.comboBoxGroup.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; … … 135 157 // comboBoxYVariable 136 158 // 137 this.comboBoxYVariable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 159 this.comboBoxYVariable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 138 160 | System.Windows.Forms.AnchorStyles.Right))); 139 161 this.comboBoxYVariable.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; … … 148 170 // comboBoxXVariable 149 171 // 150 this.comboBoxXVariable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 172 this.comboBoxXVariable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 151 173 | System.Windows.Forms.AnchorStyles.Right))); 152 174 this.comboBoxXVariable.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; … … 166 188 this.regressionGroupBox.Controls.Add(this.label4); 167 189 this.regressionGroupBox.Dock = System.Windows.Forms.DockStyle.Top; 168 this.regressionGroupBox.Location = new System.Drawing.Point(0, 1 37);190 this.regressionGroupBox.Location = new System.Drawing.Point(0, 150); 169 191 this.regressionGroupBox.Name = "regressionGroupBox"; 170 192 this.regressionGroupBox.Size = new System.Drawing.Size(172, 78); … … 175 197 // regressionTypeComboBox 176 198 // 177 this.regressionTypeComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 199 this.regressionTypeComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 178 200 | System.Windows.Forms.AnchorStyles.Right))); 179 201 this.regressionTypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; … … 187 209 // polynomialRegressionOrderNumericUpDown 188 210 // 189 this.polynomialRegressionOrderNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 211 this.polynomialRegressionOrderNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 190 212 | System.Windows.Forms.AnchorStyles.Right))); 191 213 this.polynomialRegressionOrderNumericUpDown.Location = new System.Drawing.Point(51, 47); … … 244 266 // 245 267 this.splitContainer1.Panel2.Controls.Add(this.scatterPlotControl); 268 this.splitContainer1.Panel2.Controls.Add(this.gradientPanel); 246 269 this.splitContainer1.Size = new System.Drawing.Size(863, 517); 247 270 this.splitContainer1.SplitterDistance = 172; 248 271 this.splitContainer1.TabIndex = 5; 272 // 273 // gradientPanel 274 // 275 this.gradientPanel.Controls.Add(this.gradientPictureBox); 276 this.gradientPanel.Controls.Add(this.gradientMinimumLabel); 277 this.gradientPanel.Controls.Add(this.gradientMaximumLabel); 278 this.gradientPanel.Dock = System.Windows.Forms.DockStyle.Right; 279 this.gradientPanel.Location = new System.Drawing.Point(618, 0); 280 this.gradientPanel.Name = "gradientPanel"; 281 this.gradientPanel.Size = new System.Drawing.Size(69, 517); 282 this.gradientPanel.TabIndex = 1; 283 // 284 // gradientMinimumLabel 285 // 286 this.gradientMinimumLabel.BackColor = System.Drawing.Color.Transparent; 287 this.gradientMinimumLabel.Dock = System.Windows.Forms.DockStyle.Bottom; 288 this.gradientMinimumLabel.Location = new System.Drawing.Point(0, 492); 289 this.gradientMinimumLabel.Name = "gradientMinimumLabel"; 290 this.gradientMinimumLabel.Size = new System.Drawing.Size(69, 25); 291 this.gradientMinimumLabel.TabIndex = 18; 292 this.gradientMinimumLabel.Text = "0.0"; 293 this.gradientMinimumLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; 294 // 295 // gradientMaximumLabel 296 // 297 this.gradientMaximumLabel.BackColor = System.Drawing.Color.Transparent; 298 this.gradientMaximumLabel.Dock = System.Windows.Forms.DockStyle.Top; 299 this.gradientMaximumLabel.Location = new System.Drawing.Point(0, 0); 300 this.gradientMaximumLabel.Name = "gradientMaximumLabel"; 301 this.gradientMaximumLabel.Size = new System.Drawing.Size(69, 25); 302 this.gradientMaximumLabel.TabIndex = 17; 303 this.gradientMaximumLabel.Text = "1.0"; 304 this.gradientMaximumLabel.TextAlign = System.Drawing.ContentAlignment.BottomCenter; 305 // 306 // gradientPictureBox 307 // 308 this.gradientPictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 309 | System.Windows.Forms.AnchorStyles.Left))); 310 this.gradientPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 311 this.gradientPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("GradientPictureBox.Image"))); 312 this.gradientPictureBox.Location = new System.Drawing.Point(17, 29); 313 this.gradientPictureBox.Name = "gradientPictureBox"; 314 this.gradientPictureBox.Size = new System.Drawing.Size(35, 460); 315 this.gradientPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; 316 this.gradientPictureBox.TabIndex = 19; 317 this.gradientPictureBox.TabStop = false; 249 318 // 250 319 // ScatterPlotSingleView … … 264 333 ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); 265 334 this.splitContainer1.ResumeLayout(false); 335 this.gradientPanel.ResumeLayout(false); 336 ((System.ComponentModel.ISupportInitialize)(this.gradientPictureBox)).EndInit(); 266 337 this.ResumeLayout(false); 267 338 … … 284 355 private System.Windows.Forms.Label label4; 285 356 private System.Windows.Forms.SplitContainer splitContainer1; 357 private System.Windows.Forms.CheckBox useGradientCheckBox; 358 private System.Windows.Forms.Panel gradientPanel; 359 private System.Windows.Forms.Label gradientMinimumLabel; 360 private System.Windows.Forms.Label gradientMaximumLabel; 361 protected System.Windows.Forms.PictureBox gradientPictureBox; 286 362 } 287 363 } -
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotSingleView.cs
r14514 r14521 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing; 24 25 using System.Linq; 25 26 using HeuristicLab.Analysis; 27 using HeuristicLab.Common; 26 28 using HeuristicLab.Core.Views; 27 29 using HeuristicLab.MainForm; 30 using HeuristicLab.MainForm.WindowsForms; 28 31 using RegressionType = HeuristicLab.Analysis.ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType; 29 32 … … 33 36 [Content(typeof(SingleScatterPlotContent), true)] 34 37 public partial class ScatterPlotSingleView : ItemView { 38 39 private readonly string NoGroupItem = "-"; 35 40 36 41 public new SingleScatterPlotContent Content { … … 55 60 comboBoxXVariable.Items.AddRange(variables.ToArray()); 56 61 comboBoxYVariable.Items.AddRange(variables.ToArray()); 57 comboBoxGroup.Items.Add( "-");62 comboBoxGroup.Items.Add(NoGroupItem); 58 63 for (int i = 0; i < Content.PreprocessingData.Columns; ++i) { 59 64 if (Content.PreprocessingData.VariableHasType<double>(i)) { 60 double distinctValueCount = Content.PreprocessingData.GetValues<double>(i).GroupBy(x => x).Count();61 if (distinctValueCount <= 20)62 65 //double distinctValueCount = Content.PreprocessingData.GetValues<double>(i).GroupBy(x => x).Count(); 66 //if (distinctValueCount <= 20) 67 comboBoxGroup.Items.Add(Content.PreprocessingData.GetVariableName(i)); 63 68 } 64 69 } … … 86 91 } 87 92 93 protected override void SetEnabledStateOfControls() { 94 base.SetEnabledStateOfControls(); 95 useGradientCheckBox.Enabled = (string)comboBoxGroup.SelectedItem != NoGroupItem; 96 gradientPanel.Visible = useGradientCheckBox.Enabled && useGradientCheckBox.Checked; ; 97 } 98 88 99 private void UpdateScatterPlot() { 89 100 if (comboBoxXVariable.SelectedItem != null && comboBoxYVariable.SelectedItem != null && comboBoxGroup.SelectedItem != null) { … … 91 102 var yVariable = (string)comboBoxYVariable.SelectedItem; 92 103 var groupVariable = (string)comboBoxGroup.SelectedItem; 104 105 bool groupingActive = useGradientCheckBox.Checked && groupVariable != NoGroupItem; 106 double min = 0, max = 1; 107 if (groupingActive) { 108 var groupValues = Content.PreprocessingData.GetValues<double>(Content.PreprocessingData.GetColumnIndex(groupVariable)) 109 .Distinct().OrderBy(x => x).ToList(); 110 min = groupValues.First(); 111 max = groupValues.Last(); 112 } 93 113 ScatterPlot scatterPlot = Content.CreateScatterPlot(xVariable, yVariable, groupVariable); 114 var rows = scatterPlot.Rows.ToList(); 115 scatterPlot.Rows.Clear(); 94 116 var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue; 95 117 int order = (int)polynomialRegressionOrderNumericUpDown.Value; 96 foreach (var row in scatterPlot.Rows) {118 foreach (var row in rows) { 97 119 row.VisualProperties.PointSize = 6; 98 120 row.VisualProperties.IsRegressionVisibleInLegend = false; 99 121 row.VisualProperties.RegressionType = regressionType; 100 122 row.VisualProperties.PolynomialRegressionOrder = order; 101 } 123 row.VisualProperties.IsVisibleInLegend = !useGradientCheckBox.Checked; 124 if (groupingActive) 125 row.VisualProperties.Color = GetColor(double.Parse(row.Name), min, max); 126 } 127 scatterPlot.Rows.AddRange(rows); 102 128 var vp = scatterPlot.VisualProperties; 103 129 vp.Title = string.Empty; … … 106 132 107 133 scatterPlotControl.Content = scatterPlot; 134 135 if (groupingActive) { 136 gradientMinimumLabel.Text = min.ToString("G5"); 137 gradientMaximumLabel.Text = max.ToString("G5"); 138 } 108 139 109 140 //save selected x and y variable in content … … 152 183 153 184 private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e) { 185 useGradientCheckBox.Enabled = (string)comboBoxGroup.SelectedItem != NoGroupItem; 186 gradientPanel.Visible = useGradientCheckBox.Enabled && useGradientCheckBox.Checked; 154 187 UpdateScatterPlot(); 155 188 } … … 159 192 var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue; 160 193 polynomialRegressionOrderNumericUpDown.Enabled = regressionType == RegressionType.Polynomial; 194 161 195 UpdateRegressionLine(); 162 196 } … … 170 204 int order = (int)polynomialRegressionOrderNumericUpDown.Value; 171 205 172 foreach (var row in scatterPlotControl.Content.Rows) { 206 var rows = scatterPlotControl.Content.Rows.ToList(); 207 scatterPlotControl.Content.Rows.Clear(); 208 foreach (var row in rows) { 173 209 row.VisualProperties.IsRegressionVisibleInLegend = false; 174 210 row.VisualProperties.RegressionType = regressionType; 175 211 row.VisualProperties.PolynomialRegressionOrder = order; 176 212 } 213 scatterPlotControl.Content.Rows.AddRange(rows); 177 214 } 178 215 #endregion 216 217 private void useGradientCheckBox_CheckedChanged(object sender, EventArgs e) { 218 gradientPanel.Visible = useGradientCheckBox.Enabled && useGradientCheckBox.Checked; 219 220 // remove rows and re-add them later to avoid firing visual property changd events 221 var rows = scatterPlotControl.Content.Rows.ToDictionary(r => r.Name, r => r); 222 scatterPlotControl.Content.Rows.Clear(); 223 224 if (useGradientCheckBox.Checked) { 225 var groupVariable = (string)comboBoxGroup.SelectedItem; 226 if (groupVariable == NoGroupItem) return; 227 228 var groupValues = Content.PreprocessingData.GetValues<double>(Content.PreprocessingData.GetColumnIndex(groupVariable)) 229 .Distinct().OrderBy(x => x).ToList(); 230 double min = groupValues.First(), max = groupValues.Last(); 231 foreach (var group in groupValues) { 232 ScatterPlotDataRow row; 233 if (rows.TryGetValue(group.ToString("R"), out row)) { 234 row.VisualProperties.Color = GetColor(group, min, max); 235 row.VisualProperties.IsVisibleInLegend = false; 236 } 237 } 238 gradientMinimumLabel.Text = min.ToString("G5"); 239 gradientMaximumLabel.Text = max.ToString("G5"); 240 } else { 241 foreach (var row in rows.Values) { 242 row.VisualProperties.Color = Color.Empty; 243 row.VisualProperties.IsVisibleInLegend = true; 244 } 245 } 246 scatterPlotControl.Content.Rows.AddRange(rows.Values); 247 } 248 249 private static Color GetColor(double value, double min, double max) { 250 if (double.IsNaN(value)) { 251 return Color.DarkGray; 252 } 253 var colors = ColorGradient.Colors; 254 int index = (int)((colors.Count - 1) * (value - min) / (max - min)); 255 if (index >= colors.Count) index = colors.Count - 1; 256 if (index < 0) index = 0; 257 return colors[index]; 258 } 259 260 private void BatchRowUpdate(Action<ScatterPlotDataRow> rowAction) { 261 var scatterPlot = scatterPlotControl.Content; 262 var rows = scatterPlot.Rows.ToList(); 263 // remove rows and re-add them later to avoid firing visual property changd events 264 scatterPlot.Rows.Clear(); 265 foreach (var row in rows) { 266 rowAction(row); 267 } 268 scatterPlot.Rows.AddRange(rows); 269 } 179 270 } 180 271 }
Note: See TracChangeset
for help on using the changeset viewer.