- Timestamp:
- 11/11/16 16:16:40 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotMultiView.cs
r14384 r14388 16 16 [Content(typeof(ScatterPlotContent), false)] 17 17 public partial class ScatterPlotMultiView : PreprocessingCheckedVariablesView { 18 private const int MaxAutoSizeElements = 6;19 private const int FixedChartWidth = 250;20 private const int FixedChartHeight = 150;21 22 18 private readonly IDictionary<string, Label> columnHeaderCache; 23 19 private readonly IDictionary<string, Label> rowHeaderCache; … … 27 23 InitializeComponent(); 28 24 25 #region Initialize Scrollbars 29 26 columnHeaderScrollPanel.HorizontalScroll.Enabled = true; 30 27 columnHeaderScrollPanel.VerticalScroll.Enabled = false; … … 42 39 bodyScrollPanel.VerticalScroll.Visible = true; 43 40 bodyScrollPanel.AutoScroll = true; 41 #endregion 44 42 45 43 columnHeaderCache = new Dictionary<string, Label>(); … … 72 70 } 73 71 72 #region Add and remove charts 74 73 private void AddChartToTable(string variable) { 75 76 } 77 // remove from headers and body and shift remaining slots to fill the gap 74 frameTableLayoutPanel.SuspendLayout(); 75 76 // find index to insert 77 var variables = checkedItemList.Content.Select(v => v.Value).ToList(); 78 int idx = variables // all variables 79 .TakeWhile(t => t != variable) // ... until the variable that was checked 80 .Count(IsVariableChecked); // ... how many checked variables 81 82 // add column header 83 var colH = columnHeaderTableLayoutPanel; 84 AddColumnHelper(colH, idx, _ => GetColumnHeader(variable)); 85 86 // add row header 87 var rowH = rowHeaderTableLayoutPanel; 88 AddRowHelper(rowH, idx, _ => GetRowHeader(variable)); 89 90 // add body 91 var body = bodyTableLayoutPanel; 92 var vars = GetCheckedVariables(); 93 var varsMinus = vars.Except(new[] { variable }).ToList(); 94 AddColumnHelper(body, idx, r => GetBody(variable, varsMinus[r])); // exclude "variable" because the row for it does not exist yet 95 AddRowHelper(body, idx, c => GetBody(vars[c], variable)); 96 97 frameTableLayoutPanel.ResumeLayout(true); 98 } 99 private void AddColumnHelper(TableLayoutPanel tlp, int idx, Func<int, Control> creatorFunc) { 100 // add column 101 tlp.ColumnCount++; 102 tlp.ColumnStyles.Insert(idx, new ColumnStyle(SizeType.Absolute, GetColumnWidth())); 103 // shift right 104 for (int c = tlp.ColumnCount; c > idx - 1; c--) { 105 for (int r = 0; r < tlp.RowCount; r++) { 106 var control = tlp.GetControlFromPosition(c, r); 107 if (control != null) { 108 tlp.SetColumn(control, c + 1); 109 } 110 } 111 } 112 // add controls 113 for (int r = 0; r < tlp.RowCount; r++) { 114 if (tlp.GetControlFromPosition(idx, r) == null) 115 tlp.Controls.Add(creatorFunc(r), idx, r); 116 } 117 118 } 119 private void AddRowHelper(TableLayoutPanel tlp, int idx, Func<int, Control> creatorFunc) { 120 // add row 121 tlp.RowCount++; 122 tlp.RowStyles.Insert(idx, new RowStyle(SizeType.Absolute, GetRowHeight())); 123 // shift right 124 for (int r = tlp.RowCount; r > idx - 1; r--) { 125 for (int c = 0; c < tlp.ColumnCount; c++) { 126 var control = tlp.GetControlFromPosition(c, r); 127 if (control != null) { 128 tlp.SetRow(control, r + 1); 129 } 130 } 131 } 132 // add controls 133 for (int c = 0; c < tlp.ColumnCount; c++) 134 if (tlp.GetControlFromPosition(c, idx) == null) 135 tlp.Controls.Add(creatorFunc(c), c, idx); 136 } 137 78 138 private void RemoveChartFromTable(string variable) { 79 139 frameTableLayoutPanel.SuspendLayout(); … … 96 156 frameTableLayoutPanel.ResumeLayout(true); 97 157 } 98 99 158 private void RemoveColumnHelper(TableLayoutPanel tlp, int idx) { 159 // remove controls 100 160 for (int r = 0; r < tlp.RowCount; r++) 101 161 tlp.Controls.Remove(tlp.GetControlFromPosition(idx, r)); 162 // shift left 102 163 for (int c = idx + 1; c < tlp.ColumnCount; c++) { 103 164 for (int r = 0; r < tlp.RowCount; r++) { … … 108 169 } 109 170 } 171 // delete column 110 172 tlp.ColumnStyles.RemoveAt(tlp.ColumnCount - 1); 111 173 tlp.ColumnCount--; 112 174 } 113 175 private void RemoveRowHelper(TableLayoutPanel tlp, int idx) { 176 // remove controls 114 177 for (int c = 0; c < tlp.ColumnCount; c++) 115 178 tlp.Controls.Remove(tlp.GetControlFromPosition(c, idx)); 179 // shift left 116 180 for (int r = idx + 1; r < tlp.RowCount; r++) { 117 181 for (int c = 0; c < tlp.ColumnCount; c++) { … … 122 186 } 123 187 } 188 // delete rows 124 189 tlp.RowStyles.RemoveAt(tlp.RowCount - 1); 125 190 tlp.RowCount--; 126 191 } 127 128 #region Add/Remove/Update Variable, Reset 192 #endregion 193 194 #region Add/Remove/Update Variable 129 195 protected override void AddVariable(string name) { 130 196 base.AddVariable(name); 131 } 132 197 if (IsVariableChecked(name)) 198 AddChartToTable(name); 199 } 133 200 protected override void RemoveVariable(string name) { 134 201 base.RemoveVariable(name); … … 147 214 protected override void UpdateVariable(string name) { 148 215 base.UpdateVariable(name); 216 RemoveVariable(name); 217 AddVariable(name); 149 218 } 150 219 protected override void ResetAllVariables() { … … 153 222 #endregion 154 223 155 156 #region Creating Header and Body 224 #region Creating Headers and Body 157 225 private Label GetColumnHeader(string variable) { 158 226 if (!columnHeaderCache.ContainsKey(variable)) { … … 214 282 #endregion 215 283 216 217 218 219 284 #region Generate Charts 220 285 private void GenerateCharts() { … … 238 303 239 304 // Set column and row layout 240 int width = variables.Count <= MaxAutoSizeElements ? bodyTableLayoutPanel.Width / variables.Count : FixedChartWidth;241 int height = variables.Count <= MaxAutoSizeElements ? bodyTableLayoutPanel.Height / variables.Count : FixedChartHeight;242 305 for (int i = 0; i < variables.Count; i++) { 243 columnHeaderTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, width));244 rowHeaderTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, height));245 bodyTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, width));246 bodyTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, height));306 columnHeaderTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, GetColumnWidth())); 307 rowHeaderTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, GetRowHeight())); 308 bodyTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, GetColumnWidth())); 309 bodyTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, GetRowHeight())); 247 310 } 248 311 … … 315 378 #endregion 316 379 380 #region Scrolling 317 381 private void bodyScrollPanel_Scroll(object sender, ScrollEventArgs e) { 318 382 SyncScroll(); … … 325 389 } 326 390 private void SyncScroll() { 327 //Debug.WriteLine("H: {0} <- {1}", columnHeaderScrollPanel.HorizontalScroll.Value, bodyScrollPanel.HorizontalScroll.Value);328 //Debug.WriteLine("V: {0} <- {1}", rowScrollLayoutPanel.VerticalScroll.Value, bodyScrollPanel.VerticalScroll.Value);329 330 391 frameTableLayoutPanel.SuspendRepaint(); 331 392 … … 344 405 frameTableLayoutPanel.ResumeRepaint(true); 345 406 } 346 347 407 // add a margin to the header table layouts if the scollbar is visible to account for the width/height of the scrollbar 348 408 private void UpdateHeaderMargin() { … … 350 410 rowHeaderScrollPanel.Margin = new Padding(0, 0, 0, bodyScrollPanel.HorizontalScroll.Visible ? SystemInformation.HorizontalScrollBarHeight : 0); 351 411 } 412 #endregion 413 414 #region Sizing of Charts 415 private int GetColumnWidth() { return (int)(bodyScrollPanel.Width * ((float)widthTrackBar.Value / 100)); } 416 private int GetRowHeight() { return (int)(bodyScrollPanel.Height * ((float)heightTrackBar.Value / 100)); } 417 private void widthTrackBar_ValueChanged(object sender, EventArgs e) { 418 frameTableLayoutPanel.SuspendRepaint(); 419 for (int i = 0; i < columnHeaderTableLayoutPanel.ColumnCount; i++) { 420 columnHeaderTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth(); 421 bodyTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth(); 422 } 423 frameTableLayoutPanel.ResumeRepaint(true); 424 } 425 private void heightTrackBar_ValueChanged(object sender, EventArgs e) { 426 frameTableLayoutPanel.SuspendRepaint(); 427 428 for (int i = 0; i < rowHeaderTableLayoutPanel.RowCount; i++) { 429 rowHeaderTableLayoutPanel.RowStyles[i].Height = GetRowHeight(); 430 bodyTableLayoutPanel.RowStyles[i].Height = GetRowHeight(); 431 } 432 frameTableLayoutPanel.ResumeRepaint(true); 433 } 434 #endregion 352 435 } 353 436 }
Note: See TracChangeset
for help on using the changeset viewer.