Changeset 14579 for branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4
- Timestamp:
- 01/18/17 11:17:19 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/HistogramView.cs
r14474 r14579 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Linq; 25 24 using HeuristicLab.Analysis; … … 27 26 28 27 namespace HeuristicLab.DataPreprocessing.Views { 29 30 28 [View("Histogram View")] 31 29 [Content(typeof(HistogramContent), true)] 32 30 public partial class HistogramView : PreprocessingChartView { 33 34 public List<double> Classification { get; set; } 35 public bool IsDetailedChartViewEnabled { get; set; } 31 public new HistogramContent Content { 32 get { return (HistogramContent)base.Content; } 33 set { base.Content = value; } 34 } 36 35 37 36 public HistogramView() { … … 41 40 protected override void OnContentChanged() { 42 41 base.OnContentChanged(); 42 classifierComboBox.Items.Clear(); 43 classifierComboBox.Items.Add(""); 44 43 45 if (Content != null) { 44 classifierComboBox.Items.Clear(); 45 classifierComboBox.Items.Add("None"); 46 47 foreach (string var in Content.GetVariableNamesForHistogramClassification()) { 46 foreach (string var in Content.GetVariableNamesForGrouping()) { 48 47 classifierComboBox.Items.Add(var); 49 48 } 50 49 51 if (classifierComboBox.SelectedItem == null && Content.ClassifierVariableIndex < classifierComboBox.Items.Count) { 52 classifierComboBox.SelectedIndex = Content.ClassifierVariableIndex; 53 } 50 classifierComboBox.SelectedItem = Content.GroupingVariableName; 54 51 } 55 52 } 56 53 57 54 protected override DataTable CreateDataTable(string variableName) { 58 var dt = new DataTable(); 59 var row = Content.CreateDataRow(variableName, DataRowVisualProperties.DataRowChartType.Histogram); 60 if (Classification == null) { 61 dt.Rows.Add(row); 62 } else { 63 dt.VisualProperties.Title = variableName; 64 var valuesPerClass = row.Values.Zip(Classification, (value, @class) => new { value, @class }) 65 .GroupBy(x => x.@class) 66 .ToDictionary(x => x.Key, x => x.Select(v => v.value)); 67 foreach (var entry in valuesPerClass) { 68 var classRow = new DataRow(string.Format("{0} ({1})", classifierComboBox.SelectedItem, entry.Key)); 69 classRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram; 70 classRow.Values.AddRange(entry.Value); 71 dt.Rows.Add(classRow); 72 } 55 var dataTable = new DataTable(); 56 57 if (string.IsNullOrEmpty(Content.GroupingVariableName)) { 58 var row = Content.CreateDataRow(variableName, DataRowVisualProperties.DataRowChartType.Histogram); 59 dataTable.Rows.Add(row); 60 return dataTable; 73 61 } 74 return dt; 62 63 dataTable.VisualProperties.Title = variableName; 64 65 int variableIndex = Content.PreprocessingData.GetColumnIndex(variableName); 66 var variableValues = Content.PreprocessingData.GetValues<double>(variableIndex); 67 int groupVariableIndex = Content.PreprocessingData.GetColumnIndex(Content.GroupingVariableName); 68 var groupingValues = Enumerable.Empty<string>(); 69 70 if (Content.PreprocessingData.VariableHasType<double>(groupVariableIndex)) { 71 groupingValues = Content.PreprocessingData.GetValues<double>(groupVariableIndex).Select(x => x.ToString()); 72 } else if (Content.PreprocessingData.VariableHasType<string>(groupVariableIndex)) { 73 groupingValues = Content.PreprocessingData.GetValues<string>(groupVariableIndex); 74 } else if (Content.PreprocessingData.VariableHasType<DateTime>(groupVariableIndex)) { 75 groupingValues = Content.PreprocessingData.GetValues<DateTime>(groupVariableIndex).Select(x => x.ToString()); 76 } 77 78 var groups = groupingValues.Zip(variableValues, Tuple.Create).GroupBy(t => t.Item1, t => t.Item2); 79 80 foreach (var group in groups) { 81 var classRow = new DataRow(); 82 classRow.Name = group.Key; 83 classRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram; 84 classRow.Values.AddRange(group); 85 dataTable.Rows.Add(classRow); 86 } 87 return dataTable; 75 88 } 76 89 77 public new HistogramContent Content {78 get { return (HistogramContent)base.Content; }79 set { base.Content = value; }80 }81 90 82 91 private void classifierComboBox_SelectedIndexChanged(object sender, EventArgs e) { 83 if (classifierComboBox.SelectedItem == null) 84 return; 85 86 if (classifierComboBox.SelectedIndex != 0) { 87 int columndIndex = Content.PreprocessingData.GetColumnIndex(classifierComboBox.SelectedItem.ToString()); 88 Classification = Content.PreprocessingData.GetValues<double>(columndIndex).ToList(); 89 } else { 90 Classification = null; 91 } 92 93 Content.ClassifierVariableIndex = classifierComboBox.SelectedIndex; 92 Content.GroupingVariableName = classifierComboBox.SelectedItem.ToString(); 94 93 95 94 // rebuild datatables
Note: See TracChangeset
for help on using the changeset viewer.