Changeset 10867
- Timestamp:
- 05/21/14 11:12:31 (11 years ago)
- Location:
- branches/DataPreprocessing
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/HistogramView.Designer.cs
r10771 r10867 25 25 private void InitializeComponent() { 26 26 this.optionsBox = new System.Windows.Forms.GroupBox(); 27 this.allInOneCheckBox = new System.Windows.Forms.CheckBox(); 27 this.label1 = new System.Windows.Forms.Label(); 28 this.classifierComboBox = new System.Windows.Forms.ComboBox(); 28 29 this.optionsBox.SuspendLayout(); 29 30 this.SuspendLayout(); … … 32 33 // 33 34 this.optionsBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 34 this.optionsBox.Controls.Add(this.allInOneCheckBox); 35 this.optionsBox.Controls.Add(this.label1); 36 this.optionsBox.Controls.Add(this.classifierComboBox); 35 37 this.optionsBox.Location = new System.Drawing.Point(4, 263); 36 38 this.optionsBox.Name = "optionsBox"; … … 40 42 this.optionsBox.Text = "Options"; 41 43 // 42 // allInOneCheckBox44 // label1 43 45 // 44 this.allInOneCheckBox.AutoSize = true; 45 this.allInOneCheckBox.Location = new System.Drawing.Point(6, 19); 46 this.allInOneCheckBox.Name = "allInOneCheckBox"; 47 this.allInOneCheckBox.Size = new System.Drawing.Size(69, 17); 48 this.allInOneCheckBox.TabIndex = 0; 49 this.allInOneCheckBox.Text = "All in one"; 50 this.allInOneCheckBox.UseVisualStyleBackColor = true; 51 this.allInOneCheckBox.CheckedChanged += new System.EventHandler(this.allInOneCheckBox_CheckedChanged); 46 this.label1.AutoSize = true; 47 this.label1.Location = new System.Drawing.Point(6, 26); 48 this.label1.Name = "label1"; 49 this.label1.Size = new System.Drawing.Size(91, 13); 50 this.label1.TabIndex = 2; 51 this.label1.Text = "Classifier variable:"; 52 // 53 // classifierComboBox 54 // 55 this.classifierComboBox.FormattingEnabled = true; 56 this.classifierComboBox.Location = new System.Drawing.Point(6, 52); 57 this.classifierComboBox.Name = "classifierComboBox"; 58 this.classifierComboBox.Size = new System.Drawing.Size(121, 21); 59 this.classifierComboBox.TabIndex = 1; 60 this.classifierComboBox.SelectedIndexChanged += new System.EventHandler(this.classifierComboBox_SelectedIndexChanged); 52 61 // 53 62 // HistogramView … … 67 76 68 77 private System.Windows.Forms.GroupBox optionsBox; 69 private System.Windows.Forms.CheckBox allInOneCheckBox; 78 private System.Windows.Forms.ComboBox classifierComboBox; 79 private System.Windows.Forms.Label label1; 70 80 71 81 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/HistogramView.cs
r10818 r10867 18 18 } 19 19 20 protected override void OnContentChanged() 21 { 22 base.OnContentChanged(); 23 if (Content != null) 24 { 25 logic = Content.ChartLogic; 26 Content.AllInOneMode = false; 27 28 classifierComboBox.Items.Clear(); 29 30 classifierComboBox.Items.Add("None"); 31 32 foreach(string var in logic.GetVariableNames()){ 33 classifierComboBox.Items.Add(var); 34 } 35 36 if (classifierComboBox.SelectedIndex == -1) { 37 classifierComboBox.SelectedIndex = 0; 38 } 39 } 40 } 41 20 42 public new HistogramContent Content { 21 43 get { return (HistogramContent)base.Content; } … … 23 45 } 24 46 25 private void allInOneCheckBox_CheckedChanged(object sender, EventArgs e) { 26 if (allInOneCheckBox.Checked) 27 Content.AllInOneMode = true; 28 else 29 Content.AllInOneMode = false; 47 private void classifierComboBox_SelectedIndexChanged(object sender, EventArgs e) 48 { 49 if (classifierComboBox.SelectedItem == null) 50 return; 51 52 53 if (classifierComboBox.SelectedIndex != 0) 54 { 55 classification = logic.GetVariableValues(classifierComboBox.SelectedItem.ToString()); 56 } 57 else { 58 classification = null; 59 } 60 30 61 GenerateChart(); 31 62 } 32 33 protected override void OnContentChanged()34 {35 base.OnContentChanged();36 if (Content != null)37 {38 allInOneCheckBox.Checked = Content.AllInOneMode;39 }40 }41 42 63 } 43 64 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/LineChartView.cs
r10818 r10867 45 45 46 46 private void allInOneCheckBox_CheckedChanged(object sender, EventArgs e) { 47 if (allInOneCheckBox.Checked) 48 Content.AllInOneMode = true; 49 else 50 Content.AllInOneMode = false; 47 Content.AllInOneMode = allInOneCheckBox.Checked; 48 51 49 GenerateChart(); 52 50 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/PreprocessingChartView.cs
r10847 r10867 38 38 public partial class PreprocessingChartView : ItemView { 39 39 40 private IChartLogic logic;41 40 private PreprocessingDataTable dataTable; 42 41 private List<PreprocessingDataTable> dataTablePerVariable; … … 46 45 protected DataRowVisualProperties.DataRowChartType chartType; 47 46 protected string chartTitle; 47 protected IChartLogic logic; 48 48 49 49 private const string DEFAULT_CHART_TITLE = "Chart"; 50 50 51 public List<double> classification { get; set; } 51 52 52 53 public PreprocessingChartView() { … … 335 336 336 337 PreprocessingDataTableView dataView = new PreprocessingDataTableView(); 338 dataView.classification = classification; 337 339 enumerator.MoveNext(); 338 340 PreprocessingDataTable d = enumerator.Current; -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/PreprocessingDataTableView.cs
r10851 r10867 31 31 using HeuristicLab.MainForm; 32 32 33 namespace HeuristicLab.Analysis.Views { 33 namespace HeuristicLab.Analysis.Views 34 { 34 35 [View("Preprocessing DataTable View")] 35 36 [Content(typeof(PreprocessingDataTable), false)] 36 public partial class PreprocessingDataTableView : ItemView, IConfigureableView { 37 public partial class PreprocessingDataTableView : ItemView, IConfigureableView 38 { 37 39 protected List<Series> invisibleSeries; 38 40 protected Dictionary<IObservableList<double>, DataRow> valuesRowsTable; 39 41 40 public new PreprocessingDataTable Content { 42 public new PreprocessingDataTable Content 43 { 41 44 get { return (PreprocessingDataTable)base.Content; } 42 45 set { base.Content = value; } 43 46 } 44 47 45 public PreprocessingDataTableView() { 48 public List<double> classification { get; set; } 49 50 public PreprocessingDataTableView() 51 { 46 52 InitializeComponent(); 47 53 valuesRowsTable = new Dictionary<IObservableList<double>, DataRow>(); … … 52 58 53 59 #region Event Handler Registration 54 protected override void DeregisterContentEvents() { 60 protected override void DeregisterContentEvents() 61 { 55 62 foreach (DataRow row in Content.Rows) 56 63 DeregisterDataRowEvents(row); … … 67 74 base.DeregisterContentEvents(); 68 75 } 69 protected override void RegisterContentEvents() { 76 protected override void RegisterContentEvents() 77 { 70 78 base.RegisterContentEvents(); 71 79 Content.VisualPropertiesChanged += new EventHandler(Content_VisualPropertiesChanged); … … 92 100 row.Values.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_CollectionReset); 93 101 } 94 protected virtual void DeregisterDataRowEvents(DataRow row) { 102 protected virtual void DeregisterDataRowEvents(DataRow row) 103 { 95 104 row.Values.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsAdded); 96 105 row.Values.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsRemoved); … … 104 113 #endregion 105 114 106 protected override void OnContentChanged() { 115 protected override void OnContentChanged() 116 { 107 117 base.OnContentChanged(); 108 118 invisibleSeries.Clear(); … … 111 121 chart.ChartAreas[0].AxisY2.Title = string.Empty; 112 122 chart.Series.Clear(); 113 if (Content != null) { 123 if (Content != null) 124 { 125 126 if (classification != null) 127 { 128 chart.Titles[0].Text = Content.Name; 129 } 114 130 115 131 AddDataRows(Content.Rows); … … 120 136 } 121 137 122 protected override void SetEnabledStateOfControls() { 138 protected override void SetEnabledStateOfControls() 139 { 123 140 base.SetEnabledStateOfControls(); 124 141 chart.Enabled = Content != null; 125 142 } 126 143 127 public void ShowConfiguration() { 128 if (Content != null) { 129 using (var dialog = new DataTableVisualPropertiesDialog(Content)) { 144 public void ShowConfiguration() 145 { 146 if (Content != null) 147 { 148 using (var dialog = new DataTableVisualPropertiesDialog(Content)) 149 { 130 150 dialog.ShowDialog(this); 131 151 } 132 } else MessageBox.Show("Nothing to configure."); 133 } 134 protected virtual void AddDataRows(IEnumerable<DataRow> rows) { 135 foreach (var row in rows) { 152 } 153 else MessageBox.Show("Nothing to configure."); 154 } 155 protected virtual void AddDataRows(IEnumerable<DataRow> rows) 156 { 157 foreach (var row in rows) 158 { 136 159 RegisterDataRowEvents(row); 137 160 var series = new Series(row.Name); … … 140 163 ConfigureSeries(series, row); 141 164 FillSeriesWithRowValues(series, row); 142 chart.Series.Add(series); 165 166 if (classification == null) 167 { 168 chart.Series.Add(series); 169 } 143 170 } 144 171 … … 172 199 ConfigureSeries(series, row); 173 200 FillSeriesWithRowValues(series, row); 174 chart.Series.Add(series); 201 202 if (classification == null) 203 { 204 chart.Series.Add(series); 205 } 206 175 207 } 176 208 } … … 202 234 } 203 235 204 private void ConfigureSeries(Series series, DataRow row) { 236 private void ConfigureSeries(Series series, DataRow row) 237 { 205 238 RemoveCustomPropertyIfExists(series, "PointWidth"); 206 239 series.BorderWidth = 1; … … 223 256 if (!chart.Series.Any(x => x.ChartType != SeriesChartType.Bar && x.ChartType != SeriesChartType.StackedBar && x.ChartType != SeriesChartType.StackedBar100)) 224 257 series.ChartType = SeriesChartType.Bar; 225 else { 258 else 259 { 226 260 series.ChartType = SeriesChartType.FastPoint; //default 227 261 row.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points; … … 235 269 break; 236 270 case DataRowVisualProperties.DataRowChartType.Histogram: 237 series.ChartType = SeriesChartType. Column;271 series.ChartType = SeriesChartType.StackedColumn; 238 272 series.SetCustomProperty("PointWidth", "1"); 239 273 if (!series.Color.IsEmpty && series.Color.GetBrightness() < 0.25) … … 267 301 } 268 302 269 private void ConfigureChartArea(ChartArea area) { 303 private void ConfigureChartArea(ChartArea area) 304 { 270 305 if (Content.VisualProperties.TitleFont != null) chart.Titles[0].Font = Content.VisualProperties.TitleFont; 271 306 if (!Content.VisualProperties.TitleColor.IsEmpty) chart.Titles[0].ForeColor = Content.VisualProperties.TitleColor; … … 294 329 } 295 330 296 private void RecalculateAxesScale(ChartArea area) { 331 private void RecalculateAxesScale(ChartArea area) 332 { 297 333 // Reset the axes bounds so that RecalculateAxesScale() will assign new bounds 298 foreach (Axis a in area.Axes) { 334 foreach (Axis a in area.Axes) 335 { 299 336 a.Minimum = double.NaN; 300 337 a.Maximum = double.NaN; … … 318 355 } 319 356 320 protected virtual void UpdateYCursorInterval() { 357 protected virtual void UpdateYCursorInterval() 358 { 321 359 double interestingValuesRange = ( 322 360 from series in chart.Series … … 337 375 #region Event Handlers 338 376 #region Content Event Handlers 339 private void Content_VisualPropertiesChanged(object sender, EventArgs e) { 377 private void Content_VisualPropertiesChanged(object sender, EventArgs e) 378 { 340 379 if (InvokeRequired) 341 380 Invoke(new EventHandler(Content_VisualPropertiesChanged), sender, e); 342 else { 381 else 382 { 343 383 ConfigureChartArea(chart.ChartAreas[0]); 344 384 RecalculateAxesScale(chart.ChartAreas[0]); // axes min/max could have changed … … 386 426 if (InvokeRequired) 387 427 Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsAdded), sender, e); 388 else { 428 else 429 { 389 430 AddDataRows(e.Items); 390 431 } 391 432 } 392 private void Rows_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<DataRow> e) { 433 private void Rows_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<DataRow> e) 434 { 393 435 if (InvokeRequired) 394 436 Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsRemoved), sender, e); 395 else { 437 else 438 { 396 439 RemoveDataRows(e.Items); 397 440 } 398 441 } 399 private void Rows_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<DataRow> e) { 442 private void Rows_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<DataRow> e) 443 { 400 444 if (InvokeRequired) 401 445 Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsReplaced), sender, e); 402 else { 446 else 447 { 403 448 RemoveDataRows(e.OldItems); 404 449 AddDataRows(e.Items); 405 450 } 406 451 } 407 private void Rows_CollectionReset(object sender, CollectionItemsChangedEventArgs<DataRow> e) { 452 private void Rows_CollectionReset(object sender, CollectionItemsChangedEventArgs<DataRow> e) 453 { 408 454 if (InvokeRequired) 409 455 Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_CollectionReset), sender, e); 410 else { 456 else 457 { 411 458 RemoveDataRows(e.OldItems); 412 459 AddDataRows(e.Items); … … 415 462 #endregion 416 463 #region Row Event Handlers 417 private void Row_VisualPropertiesChanged(object sender, EventArgs e) { 464 private void Row_VisualPropertiesChanged(object sender, EventArgs e) 465 { 418 466 if (InvokeRequired) 419 467 Invoke(new EventHandler(Row_VisualPropertiesChanged), sender, e); 420 else { 468 else 469 { 421 470 DataRow row = (DataRow)sender; 422 471 Series series = chart.Series[row.Name]; … … 427 476 } 428 477 } 429 private void Row_NameChanged(object sender, EventArgs e) { 478 private void Row_NameChanged(object sender, EventArgs e) 479 { 430 480 if (InvokeRequired) 431 481 Invoke(new EventHandler(Row_NameChanged), sender, e); 432 else { 482 else 483 { 433 484 DataRow row = (DataRow)sender; 434 485 chart.Series[row.Name].Name = row.Name; … … 437 488 #endregion 438 489 #region Values Event Handlers 439 private void Values_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) { 490 private void Values_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) 491 { 440 492 if (InvokeRequired) 441 493 Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsAdded), sender, e); 442 else { 494 else 495 { 443 496 DataRow row = null; 444 497 valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row); 445 if (row != null) { 498 if (row != null) 499 { 446 500 Series rowSeries = chart.Series[row.Name]; 447 if (!invisibleSeries.Contains(rowSeries)) { 501 if (!invisibleSeries.Contains(rowSeries)) 502 { 448 503 rowSeries.Points.Clear(); 449 504 FillSeriesWithRowValues(rowSeries, row); … … 454 509 } 455 510 } 456 private void Values_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) { 511 private void Values_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) 512 { 457 513 if (InvokeRequired) 458 514 Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsRemoved), sender, e); 459 else { 515 else 516 { 460 517 DataRow row = null; 461 518 valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row); 462 if (row != null) { 519 if (row != null) 520 { 463 521 Series rowSeries = chart.Series[row.Name]; 464 if (!invisibleSeries.Contains(rowSeries)) { 522 if (!invisibleSeries.Contains(rowSeries)) 523 { 465 524 rowSeries.Points.Clear(); 466 525 FillSeriesWithRowValues(rowSeries, row); … … 471 530 } 472 531 } 473 private void Values_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) { 532 private void Values_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) 533 { 474 534 if (InvokeRequired) 475 535 Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsReplaced), sender, e); 476 else { 536 else 537 { 477 538 DataRow row = null; 478 539 valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row); 479 if (row != null) { 540 if (row != null) 541 { 480 542 Series rowSeries = chart.Series[row.Name]; 481 if (!invisibleSeries.Contains(rowSeries)) { 482 if (row.VisualProperties.ChartType == DataRowVisualProperties.DataRowChartType.Histogram) { 543 if (!invisibleSeries.Contains(rowSeries)) 544 { 545 if (row.VisualProperties.ChartType == DataRowVisualProperties.DataRowChartType.Histogram) 546 { 483 547 rowSeries.Points.Clear(); 484 548 FillSeriesWithRowValues(rowSeries, row); 485 } else { 486 foreach (IndexedItem<double> item in e.Items) { 549 } 550 else 551 { 552 foreach (IndexedItem<double> item in e.Items) 553 { 487 554 if (IsInvalidValue(item.Value)) 488 555 rowSeries.Points[item.Index].IsEmpty = true; 489 else { 556 else 557 { 490 558 rowSeries.Points[item.Index].YValues = new double[] { item.Value }; 491 559 rowSeries.Points[item.Index].IsEmpty = false; … … 499 567 } 500 568 } 501 private void Values_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) { 569 private void Values_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) 570 { 502 571 if (InvokeRequired) 503 572 Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsMoved), sender, e); 504 else { 573 else 574 { 505 575 DataRow row = null; 506 576 valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row); 507 if (row != null) { 577 if (row != null) 578 { 508 579 Series rowSeries = chart.Series[row.Name]; 509 if (!invisibleSeries.Contains(rowSeries)) { 580 if (!invisibleSeries.Contains(rowSeries)) 581 { 510 582 rowSeries.Points.Clear(); 511 583 FillSeriesWithRowValues(rowSeries, row); … … 517 589 } 518 590 519 private void Values_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) { 591 private void Values_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) 592 { 520 593 if (InvokeRequired) 521 594 Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_CollectionReset), sender, e); 522 else { 595 else 596 { 523 597 DataRow row = null; 524 598 valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row); 525 if (row != null) { 599 if (row != null) 600 { 526 601 Series rowSeries = chart.Series[row.Name]; 527 if (!invisibleSeries.Contains(rowSeries)) { 602 if (!invisibleSeries.Contains(rowSeries)) 603 { 528 604 rowSeries.Points.Clear(); 529 605 FillSeriesWithRowValues(rowSeries, row); … … 538 614 539 615 #region Chart Event Handlers 540 private void chart_MouseDown(object sender, MouseEventArgs e) { 616 private void chart_MouseDown(object sender, MouseEventArgs e) 617 { 541 618 HitTestResult result = chart.HitTest(e.X, e.Y); 542 if (result.ChartElementType == ChartElementType.LegendItem) { 619 if (result.ChartElementType == ChartElementType.LegendItem) 620 { 543 621 ToggleSeriesVisible(result.Series); 544 622 } 545 623 } 546 private void chart_MouseMove(object sender, MouseEventArgs e) { 624 private void chart_MouseMove(object sender, MouseEventArgs e) 625 { 547 626 HitTestResult result = chart.HitTest(e.X, e.Y); 548 627 if (result.ChartElementType == ChartElementType.LegendItem) … … 551 630 this.Cursor = Cursors.Default; 552 631 } 553 private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) { 554 foreach (LegendItem legendItem in e.LegendItems) { 632 private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) 633 { 634 foreach (LegendItem legendItem in e.LegendItems) 635 { 555 636 var series = chart.Series[legendItem.SeriesName]; 556 if (series != null) { 637 if (series != null) 638 { 557 639 bool seriesIsInvisible = invisibleSeries.Contains(series); 558 foreach (LegendCell cell in legendItem.Cells) { 640 foreach (LegendCell cell in legendItem.Cells) 641 { 559 642 cell.ForeColor = seriesIsInvisible ? Color.Gray : Color.Black; 560 643 } … … 564 647 #endregion 565 648 566 private void ToggleSeriesVisible(Series series) { 567 if (!invisibleSeries.Contains(series)) { 649 private void ToggleSeriesVisible(Series series) 650 { 651 if (!invisibleSeries.Contains(series)) 652 { 568 653 series.Points.Clear(); 569 654 invisibleSeries.Add(series); 570 } else { 655 } 656 else 657 { 571 658 invisibleSeries.Remove(series); 572 if (Content != null) { 659 if (Content != null) 660 { 573 661 574 662 var row = (from r in Content.Rows … … 583 671 } 584 672 585 private void FillSeriesWithRowValues(Series series, DataRow row) { 586 switch (row.VisualProperties.ChartType) { 673 private void FillSeriesWithRowValues(Series series, DataRow row) 674 { 675 switch (row.VisualProperties.ChartType) 676 { 587 677 case DataRowVisualProperties.DataRowChartType.Histogram: 588 678 CalculateHistogram(series, row); 589 679 break; 590 default: { 680 default: 681 { 591 682 bool yLogarithmic = series.YAxisType == AxisType.Primary 592 683 ? Content.VisualProperties.YAxisLogScale … … 595 686 ? Content.VisualProperties.XAxisLogScale 596 687 : Content.VisualProperties.SecondXAxisLogScale; 597 for (int i = 0; i < row.Values.Count; i++) { 688 for (int i = 0; i < row.Values.Count; i++) 689 { 598 690 var value = row.Values[i]; 599 691 var point = new DataPoint(); … … 614 706 double min = Double.MaxValue; 615 707 616 foreach (double value in values) { 708 foreach (double value in values) 709 { 617 710 if (!Double.IsNaN(value) && value < min) 618 711 min = value; … … 622 715 623 716 //get maximium ignores nan values 624 private double GetMaximum(IEnumerable<double> values) { 717 private double GetMaximum(IEnumerable<double> values) 718 { 625 719 double max = Double.MinValue; 626 720 627 foreach (double value in values) { 721 foreach (double value in values) 722 { 628 723 if (!Double.IsNaN(value) && value > max) 629 724 max = value; … … 632 727 } 633 728 634 protected virtual void CalculateHistogram(Series series, DataRow row) { 635 series.Points.Clear(); 729 protected virtual void CalculateHistogram(Series series, DataRow row) 730 { 731 if (classification != null) 732 { 733 734 var qry = row.Values.Select((i, index) => new { i, j = classification[index] }) 735 .GroupBy((x) => x.j).ToDictionary(x => x.Key, x => x.Select(v => v.i).ToList()); 736 chart.Titles.Add(row.Name); 737 foreach (KeyValuePair<double, List<double>> entry in qry) 738 { 739 var s = new Series(row.Name + entry.Key); 740 741 ConfigureSeries(s, row); 742 AddPointsToHistogramSeries(s, row, entry.Value); 743 744 s.LegendText = entry.Key.ToString(); 745 746 chart.Series.Add(s); 747 } 748 } 749 else 750 { 751 series.Points.Clear(); 752 ConfigureSeries(series, row); 753 AddPointsToHistogramSeries(series, row, null); 754 } 755 } 756 757 private void AddPointsToHistogramSeries(Series series, DataRow row, List<double> values) 758 { 759 636 760 if (!row.Values.Any()) return; 637 761 int bins = row.VisualProperties.Bins; … … 641 765 double intervalWidth = (maxValue - minValue) / bins; 642 766 if (intervalWidth < 0) return; 643 if (intervalWidth == 0) { 767 if (intervalWidth == 0) 768 { 644 769 series.Points.AddXY(minValue, row.Values.Count); 645 770 return; … … 673 798 var doubleRange = DoubleRange(min, max, intervalWidth).Skip(1).ToList(); 674 799 800 801 if (values == null) { 802 values = row.Values.ToList(); ; 803 } 804 675 805 // aggregate the row values by unique key and frequency value 676 var valueFrequencies = (from v in row.Values806 var valueFrequencies = (from v in values 677 807 where !IsInvalidValue(v) 678 808 orderby v … … 680 810 select new Tuple<double, double>(g.First(), g.Count())).ToList(); 681 811 682 // shift the chart to the left so the bars are placed on the intervals683 if ( valueFrequencies.First().Item1 < doubleRange.First())812 // shift the chart to the left so the bars are placed on the intervals 813 if (classification != null || valueFrequencies.First().Item1 < doubleRange.First()) { 684 814 series.Points.Add(new DataPoint(min - intervalWidth, 0)); 815 series.Points.Add(new DataPoint(max + intervalWidth, 0)); 816 } 685 817 686 818 // add data points 687 819 int j = 0; 688 foreach (var d in doubleRange) { 820 foreach (var d in doubleRange) 821 { 689 822 double sum = 0.0; 690 823 // sum the frequency values that fall within the same interval 691 while (j < valueFrequencies.Count && valueFrequencies[j].Item1 < d) { 824 while (j < valueFrequencies.Count && valueFrequencies[j].Item1 < d) 825 { 692 826 sum += valueFrequencies[j].Item2; 693 827 ++j; … … 699 833 ? "Y" 700 834 : Content.VisualProperties.YAxisTitle; 701 series.Points.Add(new DataPoint(d - intervalCenter, sum) { 835 series.Points.Add(new DataPoint(d - intervalCenter, sum) 836 { 702 837 ToolTip = 703 838 xAxisTitle + ": [" + (d - intervalWidth) + "-" + d + ")" + Environment.NewLine + … … 708 843 709 844 #region Helpers 710 public static IEnumerable<double> DoubleRange(double min, double max, double step) { 845 public static IEnumerable<double> DoubleRange(double min, double max, double step) 846 { 711 847 double i; 712 848 for (i = min; i <= max; i += step) … … 717 853 } 718 854 719 protected void RemoveCustomPropertyIfExists(Series series, string property) { 855 protected void RemoveCustomPropertyIfExists(Series series, string property) 856 { 720 857 if (series.IsCustomPropertySet(property)) series.DeleteCustomProperty(property); 721 858 } 722 859 723 private double HumanRoundRange(double range) { 860 private double HumanRoundRange(double range) 861 { 724 862 double base10 = Math.Pow(10.0, Math.Floor(Math.Log10(range))); 725 863 double rounding = range / base10; … … 732 870 } 733 871 734 private double HumanRoundMax(double max) { 872 private double HumanRoundMax(double max) 873 { 735 874 double base10; 736 875 if (max > 0) base10 = Math.Pow(10.0, Math.Floor(Math.Log10(max))); … … 741 880 } 742 881 743 private ChartDashStyle ConvertLineStyle(DataRowVisualProperties.DataRowLineStyle dataRowLineStyle) { 744 switch (dataRowLineStyle) { 882 private ChartDashStyle ConvertLineStyle(DataRowVisualProperties.DataRowLineStyle dataRowLineStyle) 883 { 884 switch (dataRowLineStyle) 885 { 745 886 case DataRowVisualProperties.DataRowLineStyle.Dash: 746 887 return ChartDashStyle.Dash; … … 760 901 } 761 902 762 protected static bool IsInvalidValue(double x) { 903 protected static bool IsInvalidValue(double x) 904 { 763 905 return double.IsNaN(x) || x < (double)decimal.MinValue || x > (double)decimal.MaxValue; 764 906 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/ChartLogic.cs
r10851 r10867 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using System.Drawing; 25 26 using HeuristicLab.Analysis; … … 68 69 } 69 70 71 public List<double> GetVariableValues(string variableName) { 72 return preprocessingData.GetValues<double>(preprocessingData.GetColumnIndex(variableName)).ToList(); 73 } 70 74 71 72 private IEnumerable<string> GetVariableNames() { 75 public IEnumerable<string> GetVariableNames() { 73 76 List<string> doubleVariableNames = new List<string>(); 74 77 … … 118 121 if(row != null) 119 122 dataRows.Add(row); 120 123 } 121 124 return dataRows; 122 125 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/IChartLogic.cs
r10847 r10867 46 46 47 47 string GetVariableNameByIndex(int index); 48 49 IEnumerable<string> GetVariableNames(); 50 List<double> GetVariableValues(string variableName); 48 51 } 49 52 }
Note: See TracChangeset
for help on using the changeset viewer.