Changeset 14975 for branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotMultiView.cs
- Timestamp:
- 05/12/17 13:41:46 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotMultiView.cs
r14953 r14975 31 31 using HeuristicLab.MainForm; 32 32 using HeuristicLab.MainForm.WindowsForms; 33 using AggregationType = HeuristicLab.Analysis.DataRowVisualProperties.DataRowHistogramAggregation; 33 34 using RegressionType = HeuristicLab.Analysis.ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType; 34 35 … … 50 51 regressionTypeComboBox.SelectedItem = RegressionType.None; 51 52 53 aggregationComboBox.DataSource = Enum.GetValues(typeof(AggregationType)); 54 aggregationComboBox.SelectedItem = AggregationType.Overlapping; 55 52 56 #region Initialize Scrollbars 53 57 columnHeaderScrollPanel.HorizontalScroll.Enabled = true; … … 85 89 groupingComboBox.SelectedItem = Content.GroupingVariable; 86 90 91 // uncheck variables that max 20 vars are selected initially 92 var list = Content.VariableItemList; 93 int numChecked = list.CheckedItems.Count(); 94 if (numChecked > 20) { 95 string message = string.Format("Displaying {0} variables ({1} charts) can cause HeuristicLab to become instable. " + 96 "Should the number of initially checked variables be reduced to 20?", 97 numChecked, numChecked * numChecked); 98 if (MessageBox.Show(this, message, "Reduce befor continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { 99 suppressCheckedChangedUpdate = true; 100 foreach (var var in list.CheckedItems.Reverse().Take(numChecked - 20)) { 101 Content.VariableItemList.SetItemCheckedState(var.Value, false); 102 } 103 suppressCheckedChangedUpdate = false; 104 } 105 } 87 106 GenerateCharts(true); 88 107 } … … 93 112 var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue; 94 113 polynomialRegressionOrderNumericUpDown.Enabled = regressionType == RegressionType.Polynomial; 114 sizeGroupBox.Enabled = Content != null; 115 pointsGroupBox.Enabled = Content != null; 116 groupingComboBox.Enabled = Content != null; 117 regressionGroupBox.Enabled = Content != null; 95 118 } 96 119 97 120 protected override void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) { 98 121 base.CheckedItemsChanged(sender, checkedItems); 99 if (suppressCheckedChangedUpdate) 100 return; 101 foreach (var variable in checkedItems.Items .Select(i => i.Value.Value)) {102 if ( IsVariableChecked(variable))103 AddChartToTable(variable);122 if (suppressCheckedChangedUpdate) return; 123 124 foreach (var variable in checkedItems.Items) { 125 if (Content.VariableItemList.ItemChecked(variable.Value)) 126 ShowChartOnTable(variable.Value.Value, variable.Index); 104 127 else 105 RemoveChartFromTable(variable); 106 } 107 } 108 109 #region Add and remove charts 128 HideChartFromTable(variable.Value.Value, variable.Index); 129 } 130 } 131 132 #region Show and Hide charts 133 private void ShowChartOnTable(string variable, int idx) { 134 frameTableLayoutPanel.SuspendLayout(); 135 136 // show column header 137 var colH = columnHeaderTableLayoutPanel; 138 colH.ColumnStyles[idx].Width = GetColumnWidth(); 139 if (colH.GetControlFromPosition(idx, 0) == null) 140 colH.Controls.Add(GetColumnHeader(variable), idx, 0); 141 else 142 colH.GetControlFromPosition(idx, 0).Visible = true; 143 144 // show row header 145 var rowH = rowHeaderTableLayoutPanel; 146 rowH.RowStyles[idx].Height = GetRowHeight(); 147 if (rowH.GetControlFromPosition(0, idx) == null) 148 rowH.Controls.Add(GetRowHeader(variable), 0, idx); 149 else 150 rowH.GetControlFromPosition(0, idx).Visible = true; 151 152 // show body 153 var body = bodyTableLayoutPanel; 154 ShowColumnHelper(body, idx, r => GetBody(variable, Content.VariableItemList[r].Value)); 155 ShowRowHelper(body, idx, c => GetBody(Content.VariableItemList[c].Value, variable)); 156 157 frameTableLayoutPanel.ResumeLayout(true); 158 } 159 private void ShowColumnHelper(TableLayoutPanel tlp, int idx, Func<int, Control> creatorFunc) { 160 tlp.ColumnStyles[idx].Width = GetColumnWidth(); 161 for (int r = 0; r < tlp.RowCount; r++) { 162 if (Content.VariableItemList.ItemChecked(Content.VariableItemList[r])) { 163 var control = tlp.GetControlFromPosition(idx, r); 164 if (control == null) 165 tlp.Controls.Add(creatorFunc(r), idx, r); 166 else 167 control.Visible = true; 168 } 169 } 170 } 171 private void ShowRowHelper(TableLayoutPanel tlp, int idx, Func<int, Control> creatorFunc) { 172 tlp.RowStyles[idx].Height = GetRowHeight(); 173 for (int c = 0; c < tlp.ColumnCount; c++) { 174 if (Content.VariableItemList.ItemChecked(Content.VariableItemList[c])) { 175 var control = tlp.GetControlFromPosition(c, idx); 176 if (control == null) 177 tlp.Controls.Add(creatorFunc(c), c, idx); 178 else 179 tlp.GetControlFromPosition(c, idx).Visible = true; 180 } 181 } 182 } 183 184 private void HideChartFromTable(string variable, int idx) { 185 frameTableLayoutPanel.SuspendLayout(); 186 187 // hide column header 188 var colH = columnHeaderTableLayoutPanel; 189 HideColumnHelper(colH, idx); 190 191 // hide row header 192 var rowH = rowHeaderTableLayoutPanel; 193 HideRowHelper(rowH, idx); 194 195 // hide from body 196 var body = bodyTableLayoutPanel; 197 HideColumnHelper(body, idx); 198 HideRowHelper(body, idx); 199 200 frameTableLayoutPanel.ResumeLayout(true); 201 } 202 private void HideColumnHelper(TableLayoutPanel tlp, int idx) { 203 tlp.ColumnStyles[idx].Width = 0; 204 // hide controls 205 for (int r = 0; r < tlp.RowCount; r++) { 206 //tlp.Controls.Remove(tlp.GetControlFromPosition(idx, r)); 207 var control = tlp.GetControlFromPosition(idx, r); 208 if (control != null) 209 control.Visible = false; 210 } 211 } 212 private void HideRowHelper(TableLayoutPanel tlp, int idx) { 213 tlp.RowStyles[idx].Height = 0; 214 // hide controls 215 for (int c = 0; c < tlp.ColumnCount; c++) { 216 //tlp.Controls.Remove(tlp.GetControlFromPosition(c, idx)); 217 var control = tlp.GetControlFromPosition(c, idx); 218 if (control != null) 219 control.Visible = false; 220 } 221 } 222 #endregion 223 224 #region Add/Remove/Update Variable 225 protected override void AddVariable(string name) { 226 base.AddVariable(name); 227 if (IsVariableChecked(name)) 228 AddChartToTable(name); 229 } 230 protected override void RemoveVariable(string name) { 231 base.RemoveVariable(name); 232 233 if (IsVariableChecked(name)) { 234 RemoveChartFromTable(name); 235 } 236 237 // clear caches 238 columnHeaderCache[name].Dispose(); 239 columnHeaderCache.Remove(name); 240 rowHeaderCache[name].Dispose(); 241 rowHeaderCache.Remove(name); 242 var keys = bodyCache.Keys.Where(t => t.Item1 == name || t.Item2 == name).ToList(); 243 foreach (var key in keys) { 244 bodyCache[key].Dispose(); 245 bodyCache.Remove(key); 246 } 247 } 248 protected override void UpdateVariable(string name) { 249 base.UpdateVariable(name); 250 RemoveVariable(name); 251 AddVariable(name); 252 } 253 protected override void ResetAllVariables() { 254 GenerateCharts(true); 255 } 256 110 257 private void AddChartToTable(string variable) { 111 258 frameTableLayoutPanel.SuspendLayout(); … … 226 373 tlp.RowStyles.RemoveAt(tlp.RowCount - 1); 227 374 tlp.RowCount--; 228 }229 #endregion230 231 #region Add/Remove/Update Variable232 protected override void AddVariable(string name) {233 base.AddVariable(name);234 if (IsVariableChecked(name))235 AddChartToTable(name);236 }237 protected override void RemoveVariable(string name) {238 base.RemoveVariable(name);239 240 // clear caches241 columnHeaderCache[name].Dispose();242 columnHeaderCache.Remove(name);243 rowHeaderCache[name].Dispose();244 rowHeaderCache.Remove(name);245 var keys = bodyCache.Keys.Where(t => t.Item1 == name || t.Item2 == name).ToList();246 foreach (var key in keys) {247 bodyCache[key].Dispose();248 bodyCache.Remove(key);249 }250 251 if (IsVariableChecked(name)) {252 RemoveChartFromTable(name);253 }254 }255 protected override void UpdateVariable(string name) {256 base.UpdateVariable(name);257 RemoveVariable(name);258 AddVariable(name);259 }260 protected override void ResetAllVariables() {261 GenerateCharts(true);262 375 } 263 376 #endregion … … 295 408 if (!bodyCache.ContainsKey(key)) { 296 409 if (rowVariable == colVariable) { // use historgram if x and y variable are equal 297 var dataTable = HistogramContent.CreateHistogram(Content.PreprocessingData, rowVariable, (string)groupingComboBox.SelectedItem, DataRowVisualProperties.DataRowHistogramAggregation.Overlapping); 410 var dataTable = HistogramContent.CreateHistogram( 411 Content.PreprocessingData, 412 rowVariable, 413 (string)groupingComboBox.SelectedItem, 414 (AggregationType)aggregationComboBox.SelectedItem); 415 dataTable.VisualProperties.Title = string.Empty; 298 416 foreach (var dataRow in dataTable.Rows) 299 dataRow.VisualProperties.IsVisibleInLegend = false; 300 417 dataRow.VisualProperties.IsVisibleInLegend = groupingComboBox.SelectedIndex > 0; 301 418 var pcv = new DataTableControl { 302 419 Name = key.ToString(), … … 309 426 bodyCache.Add(key, pcv); 310 427 } else { //scatter plot 311 var scatterPlot = ScatterPlotContent.CreateScatterPlot(Content.PreprocessingData, colVariable, rowVariable, (string)groupingComboBox.SelectedItem); 428 var scatterPlot = ScatterPlotContent.CreateScatterPlot(Content.PreprocessingData, 429 colVariable, 430 rowVariable, 431 (string)groupingComboBox.SelectedItem); 312 432 var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue; 313 433 int order = (int)polynomialRegressionOrderNumericUpDown.Value; 434 int i = 0; 435 var colors = PreprocessingChartView.Colors; 314 436 foreach (var row in scatterPlot.Rows) { 315 row.VisualProperties.PointSize = 3; 437 row.VisualProperties.PointSize = (int)pointSizeNumericUpDown.Value; 438 row.VisualProperties.Color = Color.FromArgb((int)(pointOpacityNumericUpDown.Value * 255), 439 row.VisualProperties.Color.IsEmpty ? colors[i++ % colors.Length] : row.VisualProperties.Color); 440 //row.VisualProperties.IsVisibleInLegend = true; 316 441 row.VisualProperties.IsRegressionVisibleInLegend = false; 317 442 row.VisualProperties.RegressionType = regressionType; … … 342 467 if (suppressCheckedChangedUpdate) return; 343 468 344 var variables = GetCheckedVariables();345 346 469 // Clear old layouts and cache 347 470 foreach (var tableLayoutPanel in new[] { columnHeaderTableLayoutPanel, rowHeaderTableLayoutPanel, bodyTableLayoutPanel }) { … … 362 485 } 363 486 487 var variables = Content.VariableItemList.Select(x => x.Value).ToList(); 488 364 489 // Set row and column count 365 490 columnHeaderTableLayoutPanel.ColumnCount = variables.Count; … … 370 495 // Set column and row layout 371 496 for (int i = 0; i < variables.Count; i++) { 372 columnHeaderTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, GetColumnWidth())); 373 rowHeaderTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, GetRowHeight())); 374 bodyTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, GetColumnWidth())); 375 bodyTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, GetRowHeight())); 497 bool @checked = Content.VariableItemList.ItemChecked(Content.VariableItemList[i]); 498 columnHeaderTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, @checked ? GetColumnWidth() : 0)); 499 rowHeaderTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, @checked ? GetRowHeight() : 0)); 500 bodyTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, @checked ? GetColumnWidth() : 0)); 501 bodyTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, @checked ? GetRowHeight() : 0)); 376 502 } 377 503 … … 384 510 385 511 private void AddHeaderToTableLayoutPanels() { 386 int i = 0; 387 foreach (var variable in GetCheckedVariables()) { 388 columnHeaderTableLayoutPanel.Controls.Add(GetColumnHeader(variable), i, 0); 389 rowHeaderTableLayoutPanel.Controls.Add(GetRowHeader(variable), 0, i); 390 i++; 512 for (int i = 0; i < Content.VariableItemList.Count; i++) { 513 var variable = Content.VariableItemList[i]; 514 if (Content.VariableItemList.ItemChecked(variable)) { 515 columnHeaderTableLayoutPanel.Controls.Add(GetColumnHeader(variable.Value), i, 0); 516 rowHeaderTableLayoutPanel.Controls.Add(GetRowHeader(variable.Value), 0, i); 517 } 391 518 } 392 519 } 393 520 private void AddChartsToTableLayoutPanel() { 394 int c = 0;395 foreach (var colVar in GetCheckedVariables()) {521 for (int c = 0; c < Content.VariableItemList.Count; c++) { 522 var colVar = Content.VariableItemList[c].Value; 396 523 if (!IsVariableChecked(colVar)) continue; 397 int r = 0;398 foreach (var rowVar in GetCheckedVariables()) {524 for (int r = 0; r < Content.VariableItemList.Count; r++) { 525 var rowVar = Content.VariableItemList[r].Value; 399 526 if (!IsVariableChecked(rowVar)) continue; 400 527 bodyTableLayoutPanel.Controls.Add(GetBody(colVar, rowVar), c, r); 401 r++; 402 } 403 c++; 528 } 404 529 } 405 530 UpdateRegressionLine(); … … 429 554 DataTableControl pcv = (DataTableControl)sender; 430 555 HistogramContent histoContent = new HistogramContent(Content.PreprocessingData); // create new content 431 //ToDo: histoContent.VariableItemList = Content.CreateVariableItemList();556 //ToDo: histoContent.VariableItemList = Content.CreateVariableItemList(); 432 557 var dataTable = pcv.Content; 433 558 … … 501 626 } 502 627 for (int i = 0; i < columnHeaderTableLayoutPanel.ColumnCount; i++) { 503 columnHeaderTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth(); 504 bodyTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth(); 628 if (Content.VariableItemList.ItemChecked(Content.VariableItemList[i])) { 629 columnHeaderTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth(); 630 bodyTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth(); 631 } 505 632 } 506 633 oldWidth = GetColumnWidth(); … … 516 643 } 517 644 for (int i = 0; i < rowHeaderTableLayoutPanel.RowCount; i++) { 518 rowHeaderTableLayoutPanel.RowStyles[i].Height = GetRowHeight(); 519 bodyTableLayoutPanel.RowStyles[i].Height = GetRowHeight(); 645 if (Content.VariableItemList.ItemChecked(Content.VariableItemList[i])) { 646 rowHeaderTableLayoutPanel.RowStyles[i].Height = GetRowHeight(); 647 bodyTableLayoutPanel.RowStyles[i].Height = GetRowHeight(); 648 } 520 649 } 521 650 oldWidth = GetColumnWidth(); 522 651 oldHeight = GetRowHeight(); 523 652 frameTableLayoutPanel.ResumeRepaint(true); 653 } 654 private void pointSizeNumericUpDown_ValueChanged(object sender, EventArgs e) { 655 int pointSize = (int)pointSizeNumericUpDown.Value; 656 foreach (var control in bodyCache.ToList()) { 657 var scatterPlotControl = control.Value as ScatterPlotControl; 658 if (scatterPlotControl != null) { 659 foreach (var row in scatterPlotControl.Content.Rows) { 660 row.VisualProperties.PointSize = pointSize; 661 } 662 } 663 } 664 } 665 private void pointOpacityNumericUpDown_ValueChanged(object sender, EventArgs e) { 666 float opacity = (float)pointOpacityNumericUpDown.Value; 667 foreach (var control in bodyCache.ToList()) { 668 var scatterPlotControl = control.Value as ScatterPlotControl; 669 if (scatterPlotControl != null) { 670 foreach (var row in scatterPlotControl.Content.Rows) { 671 var color = row.VisualProperties.Color; 672 if (color.IsEmpty) 673 color = PreprocessingChartView.Colors.First(); 674 row.VisualProperties.Color = Color.FromArgb((int)(opacity * 255), color); 675 } 676 } 677 } 524 678 } 525 679 #endregion … … 540 694 int order = (int)polynomialRegressionOrderNumericUpDown.Value; 541 695 542 foreach (var control in bodyCache.Values) { 543 var scatterPlotControl = control as ScatterPlotControl; 696 foreach (var control in bodyCache.ToList()) { 697 // hidden chart => reset cache 698 if (!bodyTableLayoutPanel.Controls.Contains(control.Value)) { 699 bodyCache.Remove(control.Key); 700 } 701 702 var scatterPlotControl = control.Value as ScatterPlotControl; 544 703 if (scatterPlotControl != null) { 545 704 foreach (var row in scatterPlotControl.Content.Rows) { … … 553 712 #endregion 554 713 714 #region Grouping 555 715 private void groupingComboBox_SelectedIndexChanged(object sender, EventArgs e) { 716 aggregationComboBox.Enabled = groupingComboBox.SelectedIndex > 0; 556 717 GenerateCharts(true); // new series within charts -> clear cache 557 718 } 719 720 private void aggregationComboBox_SelectedIndexChanged(object sender, EventArgs e) { 721 var aggregation = (AggregationType)aggregationComboBox.SelectedValue; 722 foreach (var control in bodyCache.ToList()) { 723 // hidden chart => reset cache 724 if (!bodyTableLayoutPanel.Controls.Contains(control.Value)) { 725 bodyCache.Remove(control.Key); 726 } 727 728 var histogramControl = control.Value as DataTableControl; 729 if (histogramControl != null) { 730 foreach (var row in histogramControl.Content.Rows) { 731 row.VisualProperties.Aggregation = aggregation; 732 } 733 } 734 } 735 } 736 #endregion 558 737 } 559 738 }
Note: See TracChangeset
for help on using the changeset viewer.