- Timestamp:
- 03/09/15 15:52:59 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessingImprovements/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs
r12151 r12165 295 295 } 296 296 297 pr ivatevoid dataGridView_KeyDown(object sender, KeyEventArgs e) {297 protected virtual void dataGridView_KeyDown(object sender, KeyEventArgs e) { 298 298 if (!ReadOnly && e.Control && e.KeyCode == Keys.V) 299 299 PasteValuesToDataGridView(); … … 398 398 } 399 399 400 pr ivatevoid dataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) {400 protected virtual void dataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { 401 401 if (Content != null) { 402 402 if (e.Button == MouseButtons.Left && Content.SortableView) { 403 bool addToSortedIndices = (Control.ModifierKeys & Keys.Control) == Keys.Control; 404 SortOrder newSortOrder = SortOrder.Ascending; 405 if (sortedColumnIndices.Any(x => x.Key == e.ColumnIndex)) { 406 SortOrder oldSortOrder = sortedColumnIndices.Where(x => x.Key == e.ColumnIndex).First().Value; 407 int enumLength = Enum.GetValues(typeof(SortOrder)).Length; 408 newSortOrder = oldSortOrder = (SortOrder)Enum.Parse(typeof(SortOrder), ((((int)oldSortOrder) + 1) % enumLength).ToString()); 409 } 410 411 if (!addToSortedIndices) 412 sortedColumnIndices.Clear(); 413 414 if (sortedColumnIndices.Any(x => x.Key == e.ColumnIndex)) { 415 int sortedIndex = sortedColumnIndices.FindIndex(x => x.Key == e.ColumnIndex); 416 if (newSortOrder != SortOrder.None) 417 sortedColumnIndices[sortedIndex] = new KeyValuePair<int, SortOrder>(e.ColumnIndex, newSortOrder); 418 else 419 sortedColumnIndices.RemoveAt(sortedIndex); 420 } else 421 if (newSortOrder != SortOrder.None) 422 sortedColumnIndices.Add(new KeyValuePair<int, SortOrder>(e.ColumnIndex, newSortOrder)); 423 Sort(); 403 SortColumn(e.ColumnIndex); 424 404 } 425 405 } … … 438 418 dataGridView.Invalidate(); 439 419 } 420 421 protected virtual void SortColumn(int columnIndex) { 422 bool addToSortedIndices = (Control.ModifierKeys & Keys.Control) == Keys.Control; 423 SortOrder newSortOrder = SortOrder.Ascending; 424 if (sortedColumnIndices.Any(x => x.Key == columnIndex)) { 425 SortOrder oldSortOrder = sortedColumnIndices.Where(x => x.Key == columnIndex).First().Value; 426 int enumLength = Enum.GetValues(typeof(SortOrder)).Length; 427 newSortOrder = oldSortOrder = (SortOrder)Enum.Parse(typeof(SortOrder), ((((int)oldSortOrder) + 1) % enumLength).ToString()); 428 } 429 430 if (!addToSortedIndices) 431 sortedColumnIndices.Clear(); 432 433 if (sortedColumnIndices.Any(x => x.Key == columnIndex)) { 434 int sortedIndex = sortedColumnIndices.FindIndex(x => x.Key == columnIndex); 435 if (newSortOrder != SortOrder.None) 436 sortedColumnIndices[sortedIndex] = new KeyValuePair<int, SortOrder>(columnIndex, newSortOrder); 437 else 438 sortedColumnIndices.RemoveAt(sortedIndex); 439 } else 440 if (newSortOrder != SortOrder.None) 441 sortedColumnIndices.Add(new KeyValuePair<int, SortOrder>(columnIndex, newSortOrder)); 442 Sort(); 443 } 444 440 445 protected virtual int[] Sort(IEnumerable<KeyValuePair<int, SortOrder>> sortedColumns) { 441 446 int[] newSortedIndex = Enumerable.Range(0, Content.Rows).ToArray(); … … 510 515 } 511 516 512 pr ivatevoid dataGridView_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) {517 protected virtual void dataGridView_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) { 513 518 if (Content == null) return; 514 519 if (e.Button == MouseButtons.Right && Content.ColumnNames.Count() != 0) … … 543 548 544 549 protected virtual void dataGridView_SelectionChanged(object sender, EventArgs e) { 545 string stringFormat = "{0,20:0.0000}";546 550 statisticsTextBox.Text = string.Empty; 547 551 if (dataGridView.SelectedCells.Count > 1) { … … 553 557 } 554 558 if (selectedValues.Count > 1) { 555 StringBuilder labelText = new StringBuilder(); 556 labelText.Append("Count: " + string.Format(stringFormat, selectedValues.Count) + " "); 557 labelText.Append("Sum: " + string.Format(stringFormat, selectedValues.Sum()) + " "); 558 labelText.Append("Min: " + string.Format(stringFormat, selectedValues.Min()) + " "); 559 labelText.Append("Max: " + string.Format(stringFormat, selectedValues.Max()) + " "); 560 labelText.Append("Average: " + string.Format(stringFormat, selectedValues.Average()) + " "); 561 labelText.Append("Standard Deviation: " + string.Format(stringFormat, selectedValues.StandardDeviation()) + " "); 562 563 statisticsTextBox.Text = labelText.ToString(); 564 } 565 } 559 statisticsTextBox.Text = CreateStatisticsText(selectedValues); 560 } 561 } 562 } 563 564 protected virtual string CreateStatisticsText(ICollection<double> values) { 565 string stringFormat = "{0,20:0.0000}"; 566 int overallCount = values.Count; 567 values = values.Where(x => !double.IsNaN(x)).ToList(); 568 StringBuilder statisticsText = new StringBuilder(); 569 statisticsText.Append("Count: " + values.Count + " "); 570 statisticsText.Append("Sum: " + string.Format(stringFormat, values.Sum()) + " "); 571 statisticsText.Append("Min: " + string.Format(stringFormat, values.Min()) + " "); 572 statisticsText.Append("Max: " + string.Format(stringFormat, values.Max()) + " "); 573 statisticsText.Append("Average: " + string.Format(stringFormat, values.Average()) + " "); 574 statisticsText.Append("Standard Deviation: " + string.Format(stringFormat, values.StandardDeviation()) + " "); 575 if (overallCount > 0) 576 statisticsText.Append("Missing Values: " + string.Format(stringFormat, ((overallCount - values.Count) / (double)overallCount) * 100) + "% "); 577 return statisticsText.ToString(); 566 578 } 567 579 }
Note: See TracChangeset
for help on using the changeset viewer.