[14902] | 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;
|
---|
[10882] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Drawing;
|
---|
| 25 | using System.Linq;
|
---|
| 26 | using System.Windows.Forms;
|
---|
| 27 | using HeuristicLab.Analysis;
|
---|
[14446] | 28 | using HeuristicLab.Analysis.Views;
|
---|
[14381] | 29 | using HeuristicLab.Collections;
|
---|
| 30 | using HeuristicLab.Data;
|
---|
[10882] | 31 | using HeuristicLab.MainForm;
|
---|
[14381] | 32 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[14514] | 33 | using RegressionType = HeuristicLab.Analysis.ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType;
|
---|
[10882] | 34 |
|
---|
| 35 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
[10987] | 36 | [View("Scatter Plot Multi View")]
|
---|
[14462] | 37 | [Content(typeof(MultiScatterPlotContent), true)]
|
---|
[14381] | 38 | public partial class ScatterPlotMultiView : PreprocessingCheckedVariablesView {
|
---|
[14580] | 39 | private readonly IDictionary<string, Label> columnHeaderCache = new Dictionary<string, Label>();
|
---|
| 40 | private readonly IDictionary<string, VerticalLabel> rowHeaderCache = new Dictionary<string, VerticalLabel>();
|
---|
| 41 | private readonly IDictionary<Tuple<string/*col*/, string/*row*/>, Control> bodyCache = new Dictionary<Tuple<string, string>, Control>();
|
---|
[14384] | 42 |
|
---|
[10987] | 43 | public ScatterPlotMultiView() {
|
---|
[10882] | 44 | InitializeComponent();
|
---|
[14381] | 45 |
|
---|
[14514] | 46 | regressionTypeComboBox.DataSource = Enum.GetValues(typeof(RegressionType));
|
---|
| 47 | regressionTypeComboBox.SelectedItem = RegressionType.None;
|
---|
| 48 |
|
---|
[14388] | 49 | #region Initialize Scrollbars
|
---|
[14384] | 50 | columnHeaderScrollPanel.HorizontalScroll.Enabled = true;
|
---|
| 51 | columnHeaderScrollPanel.VerticalScroll.Enabled = false;
|
---|
| 52 | columnHeaderScrollPanel.HorizontalScroll.Visible = false;
|
---|
| 53 | columnHeaderScrollPanel.VerticalScroll.Visible = false;
|
---|
[14381] | 54 |
|
---|
[14384] | 55 | rowHeaderScrollPanel.HorizontalScroll.Enabled = false;
|
---|
| 56 | rowHeaderScrollPanel.VerticalScroll.Enabled = true;
|
---|
| 57 | rowHeaderScrollPanel.HorizontalScroll.Visible = false;
|
---|
| 58 | rowHeaderScrollPanel.VerticalScroll.Visible = false;
|
---|
[14381] | 59 |
|
---|
[14384] | 60 | bodyScrollPanel.HorizontalScroll.Enabled = true;
|
---|
| 61 | bodyScrollPanel.VerticalScroll.Enabled = true;
|
---|
| 62 | bodyScrollPanel.HorizontalScroll.Visible = true;
|
---|
| 63 | bodyScrollPanel.VerticalScroll.Visible = true;
|
---|
| 64 | bodyScrollPanel.AutoScroll = true;
|
---|
[14388] | 65 | #endregion
|
---|
[14381] | 66 |
|
---|
[14384] | 67 | bodyScrollPanel.MouseWheel += bodyScrollPanel_MouseWheel;
|
---|
[10882] | 68 | }
|
---|
| 69 |
|
---|
[14462] | 70 | public new MultiScatterPlotContent Content {
|
---|
| 71 | get { return (MultiScatterPlotContent)base.Content; }
|
---|
[10882] | 72 | set { base.Content = value; }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | protected override void OnContentChanged() {
|
---|
| 76 | base.OnContentChanged();
|
---|
| 77 | if (Content != null) {
|
---|
[14725] | 78 | groupingComboBox.Items.Add("");
|
---|
| 79 | foreach (string var in PreprocessingChartContent.GetVariableNamesForGrouping(Content.PreprocessingData)) {
|
---|
| 80 | groupingComboBox.Items.Add(var);
|
---|
| 81 | }
|
---|
| 82 | groupingComboBox.SelectedItem = Content.GroupingVariable;
|
---|
| 83 |
|
---|
[14381] | 84 | GenerateCharts();
|
---|
[10882] | 85 | }
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[14514] | 88 | protected override void SetEnabledStateOfControls() {
|
---|
| 89 | base.SetEnabledStateOfControls();
|
---|
| 90 | var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
|
---|
| 91 | polynomialRegressionOrderNumericUpDown.Enabled = regressionType == RegressionType.Polynomial;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[14381] | 94 | protected override void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
|
---|
| 95 | base.CheckedItemsChanged(sender, checkedItems);
|
---|
[14511] | 96 | if (suppressCheckedChangedUpdate)
|
---|
| 97 | return;
|
---|
[14384] | 98 | foreach (var variable in checkedItems.Items.Select(i => i.Value.Value)) {
|
---|
| 99 | if (IsVariableChecked(variable))
|
---|
| 100 | AddChartToTable(variable);
|
---|
| 101 | else
|
---|
| 102 | RemoveChartFromTable(variable);
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
[10952] | 105 |
|
---|
[14388] | 106 | #region Add and remove charts
|
---|
[14384] | 107 | private void AddChartToTable(string variable) {
|
---|
[14388] | 108 | frameTableLayoutPanel.SuspendLayout();
|
---|
[14384] | 109 |
|
---|
[14388] | 110 | // find index to insert
|
---|
[14511] | 111 | var variables = Content.VariableItemList.Select(v => v.Value).ToList();
|
---|
[14388] | 112 | int idx = variables // all variables
|
---|
| 113 | .TakeWhile(t => t != variable) // ... until the variable that was checked
|
---|
| 114 | .Count(IsVariableChecked); // ... how many checked variables
|
---|
| 115 |
|
---|
| 116 | // add column header
|
---|
| 117 | var colH = columnHeaderTableLayoutPanel;
|
---|
| 118 | AddColumnHelper(colH, idx, _ => GetColumnHeader(variable));
|
---|
| 119 |
|
---|
| 120 | // add row header
|
---|
| 121 | var rowH = rowHeaderTableLayoutPanel;
|
---|
| 122 | AddRowHelper(rowH, idx, _ => GetRowHeader(variable));
|
---|
| 123 |
|
---|
| 124 | // add body
|
---|
| 125 | var body = bodyTableLayoutPanel;
|
---|
| 126 | var vars = GetCheckedVariables();
|
---|
| 127 | var varsMinus = vars.Except(new[] { variable }).ToList();
|
---|
| 128 | AddColumnHelper(body, idx, r => GetBody(variable, varsMinus[r])); // exclude "variable" because the row for it does not exist yet
|
---|
| 129 | AddRowHelper(body, idx, c => GetBody(vars[c], variable));
|
---|
| 130 |
|
---|
| 131 | frameTableLayoutPanel.ResumeLayout(true);
|
---|
[14381] | 132 | }
|
---|
[14388] | 133 | private void AddColumnHelper(TableLayoutPanel tlp, int idx, Func<int, Control> creatorFunc) {
|
---|
| 134 | // add column
|
---|
| 135 | tlp.ColumnCount++;
|
---|
| 136 | tlp.ColumnStyles.Insert(idx, new ColumnStyle(SizeType.Absolute, GetColumnWidth()));
|
---|
| 137 | // shift right
|
---|
[14580] | 138 | for (int c = tlp.ColumnCount; c > idx - 1; c--) {
|
---|
[14388] | 139 | for (int r = 0; r < tlp.RowCount; r++) {
|
---|
| 140 | var control = tlp.GetControlFromPosition(c, r);
|
---|
| 141 | if (control != null) {
|
---|
| 142 | tlp.SetColumn(control, c + 1);
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 | }
|
---|
| 146 | // add controls
|
---|
| 147 | for (int r = 0; r < tlp.RowCount; r++) {
|
---|
| 148 | if (tlp.GetControlFromPosition(idx, r) == null)
|
---|
| 149 | tlp.Controls.Add(creatorFunc(r), idx, r);
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | }
|
---|
| 153 | private void AddRowHelper(TableLayoutPanel tlp, int idx, Func<int, Control> creatorFunc) {
|
---|
| 154 | // add row
|
---|
| 155 | tlp.RowCount++;
|
---|
| 156 | tlp.RowStyles.Insert(idx, new RowStyle(SizeType.Absolute, GetRowHeight()));
|
---|
| 157 | // shift right
|
---|
| 158 | for (int r = tlp.RowCount; r > idx - 1; r--) {
|
---|
| 159 | for (int c = 0; c < tlp.ColumnCount; c++) {
|
---|
| 160 | var control = tlp.GetControlFromPosition(c, r);
|
---|
| 161 | if (control != null) {
|
---|
| 162 | tlp.SetRow(control, r + 1);
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | // add controls
|
---|
| 167 | for (int c = 0; c < tlp.ColumnCount; c++)
|
---|
| 168 | if (tlp.GetControlFromPosition(c, idx) == null)
|
---|
| 169 | tlp.Controls.Add(creatorFunc(c), c, idx);
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[14384] | 172 | private void RemoveChartFromTable(string variable) {
|
---|
| 173 | frameTableLayoutPanel.SuspendLayout();
|
---|
[10987] | 174 |
|
---|
[14384] | 175 | // remove column header
|
---|
| 176 | var colH = columnHeaderTableLayoutPanel;
|
---|
| 177 | int colIdx = colH.GetColumn(colH.Controls[variable]);
|
---|
| 178 | RemoveColumnHelper(colH, colIdx);
|
---|
| 179 |
|
---|
| 180 | // remove row header
|
---|
| 181 | var rowH = rowHeaderTableLayoutPanel;
|
---|
| 182 | int rowIdx = rowH.GetRow(rowH.Controls[variable]);
|
---|
| 183 | RemoveRowHelper(rowH, rowIdx);
|
---|
| 184 |
|
---|
| 185 | // remove from body
|
---|
| 186 | var body = bodyTableLayoutPanel;
|
---|
| 187 | RemoveColumnHelper(body, colIdx);
|
---|
| 188 | RemoveRowHelper(body, rowIdx);
|
---|
| 189 |
|
---|
| 190 | frameTableLayoutPanel.ResumeLayout(true);
|
---|
| 191 | }
|
---|
| 192 | private void RemoveColumnHelper(TableLayoutPanel tlp, int idx) {
|
---|
[14388] | 193 | // remove controls
|
---|
[14384] | 194 | for (int r = 0; r < tlp.RowCount; r++)
|
---|
| 195 | tlp.Controls.Remove(tlp.GetControlFromPosition(idx, r));
|
---|
[14388] | 196 | // shift left
|
---|
[14384] | 197 | for (int c = idx + 1; c < tlp.ColumnCount; c++) {
|
---|
| 198 | for (int r = 0; r < tlp.RowCount; r++) {
|
---|
| 199 | var control = tlp.GetControlFromPosition(c, r);
|
---|
| 200 | if (control != null) {
|
---|
| 201 | tlp.SetColumn(control, c - 1);
|
---|
| 202 | }
|
---|
| 203 | }
|
---|
| 204 | }
|
---|
[14388] | 205 | // delete column
|
---|
[14384] | 206 | tlp.ColumnStyles.RemoveAt(tlp.ColumnCount - 1);
|
---|
| 207 | tlp.ColumnCount--;
|
---|
| 208 | }
|
---|
| 209 | private void RemoveRowHelper(TableLayoutPanel tlp, int idx) {
|
---|
[14388] | 210 | // remove controls
|
---|
[14384] | 211 | for (int c = 0; c < tlp.ColumnCount; c++)
|
---|
| 212 | tlp.Controls.Remove(tlp.GetControlFromPosition(c, idx));
|
---|
[14388] | 213 | // shift left
|
---|
[14384] | 214 | for (int r = idx + 1; r < tlp.RowCount; r++) {
|
---|
| 215 | for (int c = 0; c < tlp.ColumnCount; c++) {
|
---|
| 216 | var control = tlp.GetControlFromPosition(c, r);
|
---|
| 217 | if (control != null) {
|
---|
| 218 | tlp.SetRow(control, r - 1);
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 | }
|
---|
[14388] | 222 | // delete rows
|
---|
[14384] | 223 | tlp.RowStyles.RemoveAt(tlp.RowCount - 1);
|
---|
| 224 | tlp.RowCount--;
|
---|
| 225 | }
|
---|
[14388] | 226 | #endregion
|
---|
[14384] | 227 |
|
---|
[14388] | 228 | #region Add/Remove/Update Variable
|
---|
[14381] | 229 | protected override void AddVariable(string name) {
|
---|
| 230 | base.AddVariable(name);
|
---|
[14388] | 231 | if (IsVariableChecked(name))
|
---|
| 232 | AddChartToTable(name);
|
---|
[10952] | 233 | }
|
---|
[14381] | 234 | protected override void RemoveVariable(string name) {
|
---|
| 235 | base.RemoveVariable(name);
|
---|
[10952] | 236 |
|
---|
[14384] | 237 | // clear caches
|
---|
| 238 | columnHeaderCache.Remove(name);
|
---|
| 239 | rowHeaderCache.Remove(name);
|
---|
| 240 | var keys = bodyCache.Keys.Where(t => t.Item1 == name || t.Item2 == name).ToList();
|
---|
| 241 | foreach (var key in keys)
|
---|
| 242 | bodyCache.Remove(key);
|
---|
| 243 |
|
---|
| 244 | if (IsVariableChecked(name)) {
|
---|
| 245 | RemoveChartFromTable(name);
|
---|
| 246 | }
|
---|
[14381] | 247 | }
|
---|
| 248 | protected override void UpdateVariable(string name) {
|
---|
| 249 | base.UpdateVariable(name);
|
---|
[14388] | 250 | RemoveVariable(name);
|
---|
| 251 | AddVariable(name);
|
---|
[14381] | 252 | }
|
---|
| 253 | protected override void ResetAllVariables() {
|
---|
| 254 | GenerateCharts();
|
---|
| 255 | }
|
---|
| 256 | #endregion
|
---|
| 257 |
|
---|
[14580] | 258 | #region Creating Headers and Body
|
---|
[14384] | 259 | private Label GetColumnHeader(string variable) {
|
---|
| 260 | if (!columnHeaderCache.ContainsKey(variable)) {
|
---|
| 261 | columnHeaderCache.Add(variable, new Label() {
|
---|
| 262 | Text = variable,
|
---|
| 263 | TextAlign = ContentAlignment.MiddleCenter,
|
---|
| 264 | Name = variable,
|
---|
| 265 | Height = columnHeaderTableLayoutPanel.Height,
|
---|
| 266 | Dock = DockStyle.Fill,
|
---|
| 267 | Margin = new Padding(3)
|
---|
| 268 | });
|
---|
| 269 | }
|
---|
| 270 | return columnHeaderCache[variable];
|
---|
| 271 | }
|
---|
| 272 | private Label GetRowHeader(string variable) {
|
---|
| 273 | if (!rowHeaderCache.ContainsKey(variable)) {
|
---|
[14514] | 274 | rowHeaderCache.Add(variable, new VerticalLabel() {
|
---|
[14384] | 275 | Text = variable,
|
---|
| 276 | TextAlign = ContentAlignment.MiddleCenter,
|
---|
| 277 | Name = variable,
|
---|
| 278 | Width = rowHeaderTableLayoutPanel.Width,
|
---|
[14514] | 279 | Height = columnHeaderScrollPanel.Width,
|
---|
[14384] | 280 | Dock = DockStyle.Fill,
|
---|
| 281 | Margin = new Padding(3)
|
---|
| 282 | });
|
---|
| 283 | }
|
---|
| 284 | return rowHeaderCache[variable];
|
---|
| 285 | }
|
---|
[14446] | 286 | private Control GetBody(string colVariable, string rowVariable) {
|
---|
[14384] | 287 | var key = Tuple.Create(colVariable, rowVariable);
|
---|
| 288 | if (!bodyCache.ContainsKey(key)) {
|
---|
| 289 | if (rowVariable == colVariable) { // use historgram if x and y variable are equal
|
---|
[14725] | 290 | var dataTable = HistogramContent.CreateHistogram(Content.PreprocessingData, rowVariable, (string)groupingComboBox.SelectedItem, DataRowVisualProperties.DataRowHistogramAggregation.Overlapping);
|
---|
| 291 | foreach (var dataRow in dataTable.Rows)
|
---|
| 292 | dataRow.VisualProperties.IsVisibleInLegend = false;
|
---|
| 293 |
|
---|
[14459] | 294 | var pcv = new DataTableControl {
|
---|
[14384] | 295 | Name = key.ToString(),
|
---|
| 296 | Content = dataTable,
|
---|
| 297 | Dock = DockStyle.Fill,
|
---|
[14459] | 298 | //ShowLegend = false,
|
---|
| 299 | //XAxisFormat = "G3"
|
---|
[14384] | 300 | };
|
---|
[14459] | 301 | //pcv.ChartDoubleClick += HistogramDoubleClick;
|
---|
[14384] | 302 | bodyCache.Add(key, pcv);
|
---|
| 303 | } else { //scatter plot
|
---|
[14725] | 304 | var scatterPlot = ScatterPlotContent.CreateScatterPlot(Content.PreprocessingData, colVariable, rowVariable, (string)groupingComboBox.SelectedItem);
|
---|
[14514] | 305 | var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
|
---|
| 306 | int order = (int)polynomialRegressionOrderNumericUpDown.Value;
|
---|
| 307 | foreach (var row in scatterPlot.Rows) {
|
---|
[14495] | 308 | row.VisualProperties.PointSize = 3;
|
---|
[14514] | 309 | row.VisualProperties.IsRegressionVisibleInLegend = false;
|
---|
| 310 | row.VisualProperties.RegressionType = regressionType;
|
---|
| 311 | row.VisualProperties.PolynomialRegressionOrder = order;
|
---|
| 312 | }
|
---|
[14446] | 313 | scatterPlot.VisualProperties.Title = string.Empty;
|
---|
[14514] | 314 | var scatterPlotControl = new ScatterPlotControl {
|
---|
[14384] | 315 | Name = key.ToString(),
|
---|
| 316 | Content = scatterPlot,
|
---|
| 317 | Dock = DockStyle.Fill,
|
---|
[14446] | 318 | //ShowLegend = false,
|
---|
| 319 | //XAxisFormat = "G3"
|
---|
[14384] | 320 | };
|
---|
[14514] | 321 | //scatterPlotControl.DoubleClick += ScatterPlotDoubleClick; // ToDo: not working; double click is already handled by the chart
|
---|
[14446] | 322 | bodyCache.Add(key, scatterPlotControl);
|
---|
[14384] | 323 | }
|
---|
| 324 | }
|
---|
| 325 | return bodyCache[key];
|
---|
| 326 | }
|
---|
| 327 | #endregion
|
---|
| 328 |
|
---|
[14511] | 329 | protected override void CheckedChangedUpdate() {
|
---|
| 330 | GenerateCharts();
|
---|
| 331 | }
|
---|
| 332 |
|
---|
[14381] | 333 | #region Generate Charts
|
---|
| 334 | private void GenerateCharts() {
|
---|
[14511] | 335 | if (suppressCheckedChangedUpdate) return;
|
---|
| 336 |
|
---|
[14384] | 337 | var variables = GetCheckedVariables();
|
---|
[10987] | 338 |
|
---|
[14384] | 339 | // Clear old layouts and cache
|
---|
| 340 | foreach (var tableLayoutPanel in new[] { columnHeaderTableLayoutPanel, rowHeaderTableLayoutPanel, bodyTableLayoutPanel }) {
|
---|
| 341 | tableLayoutPanel.Controls.Clear();
|
---|
| 342 | tableLayoutPanel.ColumnStyles.Clear();
|
---|
| 343 | tableLayoutPanel.RowStyles.Clear();
|
---|
[14381] | 344 | }
|
---|
[14384] | 345 | columnHeaderCache.Clear();
|
---|
| 346 | rowHeaderCache.Clear();
|
---|
| 347 | bodyCache.Clear();
|
---|
[10882] | 348 |
|
---|
[14381] | 349 | // Set row and column count
|
---|
[14384] | 350 | columnHeaderTableLayoutPanel.ColumnCount = variables.Count;
|
---|
| 351 | rowHeaderTableLayoutPanel.RowCount = variables.Count;
|
---|
[14381] | 352 | bodyTableLayoutPanel.ColumnCount = variables.Count;
|
---|
| 353 | bodyTableLayoutPanel.RowCount = variables.Count;
|
---|
[10915] | 354 |
|
---|
[14381] | 355 | // Set column and row layout
|
---|
| 356 | for (int i = 0; i < variables.Count; i++) {
|
---|
[14388] | 357 | columnHeaderTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, GetColumnWidth()));
|
---|
| 358 | rowHeaderTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, GetRowHeight()));
|
---|
| 359 | bodyTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, GetColumnWidth()));
|
---|
| 360 | bodyTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, GetRowHeight()));
|
---|
[10882] | 361 | }
|
---|
[10915] | 362 |
|
---|
[14384] | 363 | frameTableLayoutPanel.SuspendLayout();
|
---|
[14381] | 364 | AddHeaderToTableLayoutPanels();
|
---|
| 365 | AddChartsToTableLayoutPanel();
|
---|
[14384] | 366 | UpdateHeaderMargin();
|
---|
| 367 | frameTableLayoutPanel.ResumeLayout(true);
|
---|
[10952] | 368 | }
|
---|
[10915] | 369 |
|
---|
[14381] | 370 | private void AddHeaderToTableLayoutPanels() {
|
---|
[14384] | 371 | int i = 0;
|
---|
| 372 | foreach (var variable in GetCheckedVariables()) {
|
---|
| 373 | columnHeaderTableLayoutPanel.Controls.Add(GetColumnHeader(variable), i, 0);
|
---|
| 374 | rowHeaderTableLayoutPanel.Controls.Add(GetRowHeader(variable), 0, i);
|
---|
| 375 | i++;
|
---|
[14381] | 376 | }
|
---|
| 377 | }
|
---|
| 378 | private void AddChartsToTableLayoutPanel() {
|
---|
[14384] | 379 | int c = 0;
|
---|
| 380 | foreach (var colVar in GetCheckedVariables()) {
|
---|
| 381 | if (!IsVariableChecked(colVar)) continue;
|
---|
| 382 | int r = 0;
|
---|
| 383 | foreach (var rowVar in GetCheckedVariables()) {
|
---|
| 384 | if (!IsVariableChecked(rowVar)) continue;
|
---|
| 385 | bodyTableLayoutPanel.Controls.Add(GetBody(colVar, rowVar), c, r);
|
---|
| 386 | r++;
|
---|
[10915] | 387 | }
|
---|
[14384] | 388 | c++;
|
---|
[10915] | 389 | }
|
---|
[14514] | 390 | UpdateRegressionLine();
|
---|
[10882] | 391 | }
|
---|
| 392 |
|
---|
[14381] | 393 | #endregion
|
---|
| 394 |
|
---|
| 395 | #region DoubleClick Events
|
---|
[10952] | 396 | //Open scatter plot in new tab with new content when double clicked
|
---|
| 397 | private void ScatterPlotDoubleClick(object sender, EventArgs e) {
|
---|
[14446] | 398 | var scatterPlotControl = (ScatterPlotControl)sender;
|
---|
[14467] | 399 | var scatterContent = new SingleScatterPlotContent(Content.PreprocessingData);
|
---|
[14446] | 400 | ScatterPlot scatterPlot = scatterPlotControl.Content;
|
---|
[10915] | 401 |
|
---|
[14381] | 402 | //Extract variable names from scatter plot and set them in content
|
---|
[10952] | 403 | if (scatterPlot.Rows.Count == 1) {
|
---|
[10992] | 404 | string[] variables = scatterPlot.Rows.ElementAt(0).Name.Split(new string[] { " - " }, StringSplitOptions.None); // extract variable names from string
|
---|
[10952] | 405 | scatterContent.SelectedXVariable = variables[0];
|
---|
| 406 | scatterContent.SelectedYVariable = variables[1];
|
---|
| 407 | }
|
---|
[14381] | 408 |
|
---|
| 409 | MainFormManager.MainForm.ShowContent(scatterContent, typeof(ScatterPlotSingleView)); // open in new tab
|
---|
[10915] | 410 | }
|
---|
[10952] | 411 |
|
---|
[14381] | 412 | //open histogram in new tab with new content when double clicked
|
---|
| 413 | private void HistogramDoubleClick(object sender, EventArgs e) {
|
---|
[14459] | 414 | DataTableControl pcv = (DataTableControl)sender;
|
---|
[14381] | 415 | HistogramContent histoContent = new HistogramContent(Content.PreprocessingData); // create new content
|
---|
[14511] | 416 | //ToDo: histoContent.VariableItemList = Content.CreateVariableItemList();
|
---|
[14459] | 417 | var dataTable = pcv.Content;
|
---|
[10952] | 418 |
|
---|
[14381] | 419 | //Set variable item list from with variable from data table
|
---|
| 420 | if (dataTable.Rows.Count == 1) { // only one data row should be in data table
|
---|
[10952] | 421 | string variableName = dataTable.Rows.ElementAt(0).Name;
|
---|
| 422 |
|
---|
| 423 | // set only variable name checked
|
---|
[10992] | 424 | foreach (var checkedItem in histoContent.VariableItemList) {
|
---|
[14381] | 425 | histoContent.VariableItemList.SetItemCheckedState(checkedItem, checkedItem.Value == variableName);
|
---|
[10952] | 426 | }
|
---|
| 427 | }
|
---|
[14381] | 428 | MainFormManager.MainForm.ShowContent(histoContent, typeof(HistogramView)); // open in new tab
|
---|
[10952] | 429 | }
|
---|
[14381] | 430 | #endregion
|
---|
[10952] | 431 |
|
---|
[14388] | 432 | #region Scrolling
|
---|
[14384] | 433 | private void bodyScrollPanel_Scroll(object sender, ScrollEventArgs e) {
|
---|
[14381] | 434 | SyncScroll();
|
---|
[10952] | 435 |
|
---|
[14384] | 436 | UpdateHeaderMargin();
|
---|
[10952] | 437 | }
|
---|
[14384] | 438 | private void bodyScrollPanel_MouseWheel(object sender, MouseEventArgs e) {
|
---|
[14381] | 439 | // Scrolling with the mouse wheel is not captured in the Scoll event
|
---|
| 440 | SyncScroll();
|
---|
| 441 | }
|
---|
| 442 | private void SyncScroll() {
|
---|
| 443 | frameTableLayoutPanel.SuspendRepaint();
|
---|
[10992] | 444 |
|
---|
[14384] | 445 | columnHeaderScrollPanel.HorizontalScroll.Minimum = bodyScrollPanel.HorizontalScroll.Minimum;
|
---|
| 446 | columnHeaderScrollPanel.HorizontalScroll.Maximum = bodyScrollPanel.HorizontalScroll.Maximum;
|
---|
| 447 | rowHeaderScrollPanel.VerticalScroll.Minimum = bodyScrollPanel.VerticalScroll.Minimum;
|
---|
| 448 | rowHeaderScrollPanel.VerticalScroll.Maximum = bodyScrollPanel.VerticalScroll.Maximum;
|
---|
[10882] | 449 |
|
---|
[14384] | 450 | columnHeaderScrollPanel.HorizontalScroll.Value = Math.Max(bodyScrollPanel.HorizontalScroll.Value, 1);
|
---|
| 451 | rowHeaderScrollPanel.VerticalScroll.Value = Math.Max(bodyScrollPanel.VerticalScroll.Value, 1);
|
---|
[14381] | 452 | // minimum 1 is nececary because of two factors:
|
---|
| 453 | // - setting the Value-property of Horizontal/VerticalScroll updates the internal state but the Value-property stays 0
|
---|
| 454 | // - setting the same number of the Value-property has no effect
|
---|
| 455 | // since the Value-property is always 0, setting it to 0 would have no effect; so it is set to 1 instead
|
---|
[10992] | 456 |
|
---|
[14381] | 457 | frameTableLayoutPanel.ResumeRepaint(true);
|
---|
| 458 | }
|
---|
[14384] | 459 | // add a margin to the header table layouts if the scollbar is visible to account for the width/height of the scrollbar
|
---|
| 460 | private void UpdateHeaderMargin() {
|
---|
| 461 | columnHeaderScrollPanel.Margin = new Padding(0, 0, bodyScrollPanel.VerticalScroll.Visible ? SystemInformation.VerticalScrollBarWidth : 0, 0);
|
---|
| 462 | rowHeaderScrollPanel.Margin = new Padding(0, 0, 0, bodyScrollPanel.HorizontalScroll.Visible ? SystemInformation.HorizontalScrollBarHeight : 0);
|
---|
| 463 | }
|
---|
[14388] | 464 | #endregion
|
---|
| 465 |
|
---|
| 466 | #region Sizing of Charts
|
---|
[14902] | 467 |
|
---|
| 468 | private int GetColumnWidth() { return (int)widthNumericUpDown.Value; }
|
---|
| 469 | private int GetRowHeight() { return (int)heightNumericUpDown.Value; }
|
---|
| 470 | private void widthNumericUpDown_ValueChanged(object sender, EventArgs e) {
|
---|
[14388] | 471 | frameTableLayoutPanel.SuspendRepaint();
|
---|
| 472 | for (int i = 0; i < columnHeaderTableLayoutPanel.ColumnCount; i++) {
|
---|
| 473 | columnHeaderTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth();
|
---|
| 474 | bodyTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth();
|
---|
| 475 | }
|
---|
| 476 | frameTableLayoutPanel.ResumeRepaint(true);
|
---|
| 477 | }
|
---|
[14902] | 478 | private void heightNumericUpDown_ValueChanged(object sender, EventArgs e) {
|
---|
[14388] | 479 | frameTableLayoutPanel.SuspendRepaint();
|
---|
| 480 | for (int i = 0; i < rowHeaderTableLayoutPanel.RowCount; i++) {
|
---|
| 481 | rowHeaderTableLayoutPanel.RowStyles[i].Height = GetRowHeight();
|
---|
| 482 | bodyTableLayoutPanel.RowStyles[i].Height = GetRowHeight();
|
---|
| 483 | }
|
---|
| 484 | frameTableLayoutPanel.ResumeRepaint(true);
|
---|
| 485 | }
|
---|
| 486 | #endregion
|
---|
[14514] | 487 |
|
---|
| 488 | #region Regression Line
|
---|
| 489 | private void regressionTypeComboBox_SelectedValueChanged(object sender, EventArgs e) {
|
---|
| 490 | var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
|
---|
| 491 | polynomialRegressionOrderNumericUpDown.Enabled = regressionType == RegressionType.Polynomial;
|
---|
| 492 | UpdateRegressionLine();
|
---|
| 493 | }
|
---|
| 494 |
|
---|
| 495 | private void polynomialRegressionOrderNumericUpDown_ValueChanged(object sender, EventArgs e) {
|
---|
| 496 | UpdateRegressionLine();
|
---|
| 497 | }
|
---|
| 498 |
|
---|
| 499 | private void UpdateRegressionLine() {
|
---|
| 500 | var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
|
---|
| 501 | int order = (int)polynomialRegressionOrderNumericUpDown.Value;
|
---|
| 502 |
|
---|
| 503 | foreach (var control in bodyCache.Values) {
|
---|
| 504 | var scatterPlotControl = control as ScatterPlotControl;
|
---|
| 505 | if (scatterPlotControl != null) {
|
---|
| 506 | foreach (var row in scatterPlotControl.Content.Rows) {
|
---|
| 507 | row.VisualProperties.IsRegressionVisibleInLegend = false;
|
---|
| 508 | row.VisualProperties.RegressionType = regressionType;
|
---|
| 509 | row.VisualProperties.PolynomialRegressionOrder = order;
|
---|
| 510 | }
|
---|
| 511 | }
|
---|
| 512 | }
|
---|
| 513 | }
|
---|
| 514 | #endregion
|
---|
[14725] | 515 |
|
---|
| 516 | private void groupingComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 517 | GenerateCharts();
|
---|
| 518 | }
|
---|
[14381] | 519 | }
|
---|
[10882] | 520 | }
|
---|
[14514] | 521 |
|
---|