Changeset 14076 for stable/HeuristicLab.DataPreprocessing.Views
- Timestamp:
- 07/14/16 22:39:50 (9 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 13838
- Property svn:mergeinfo changed
-
stable/HeuristicLab.DataPreprocessing.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.DataPreprocessing.Views merged: 13838
- Property svn:mergeinfo changed
-
stable/HeuristicLab.DataPreprocessing.Views/3.4/DataCompletenessView.cs
r14075 r14076 23 23 using System.Collections.Generic; 24 24 using System.Drawing; 25 using System.Linq; 25 26 using System.Windows.Forms; 26 27 using System.Windows.Forms.DataVisualization.Charting; … … 33 34 [Content(typeof(DataCompletenessChartContent), true)] 34 35 public partial class DataCompletenessView : ItemView { 35 36 //list of columns, bool indicates wether the cell is a missing value or not37 private List<List<bool>> matrix = new List<List<bool>>();38 36 //series colors 39 private static Color colorNonMissingVal= Color.CornflowerBlue;40 private static Color colorMissingVal= Color.Orange;37 private static readonly Color colorNonMissingValue = Color.CornflowerBlue; 38 private static readonly Color colorMissingValue = Color.Orange; 41 39 42 40 public new DataCompletenessChartContent Content { … … 44 42 set { base.Content = value; } 45 43 } 46 47 44 48 45 public DataCompletenessView() { … … 52 49 protected override void OnContentChanged() { 53 50 base.OnContentChanged(); 54 if (Content != null) { 55 InitData(); 56 } 51 if (Content == null) return; 52 InitData(); 57 53 } 58 54 59 55 private void InitData() { 60 56 IDictionary<int, IList<int>> missingValueIndices = Content.SearchLogic.GetMissingValueIndices(); 61 for (int i = 0; i < Content.SearchLogic.Columns; i++) { 62 //append column 63 List<bool> column = new List<bool>(); 64 for (int j = 0; j < Content.SearchLogic.Rows; j++) { 65 column.Add(missingValueIndices[i].Contains(j)); 66 } 67 matrix.Add(column); 57 58 bool[,] valueMissing = new bool[Content.SearchLogic.Rows, Content.SearchLogic.Columns]; 59 foreach (var columnMissingValues in missingValueIndices) { 60 var column = columnMissingValues.Key; 61 foreach (var missingValueIndex in columnMissingValues.Value) 62 valueMissing[missingValueIndex, column] = true; 68 63 } 69 List<List<int>> yValuesPerColumn = ProcessMatrixForCharting(matrix, missingValueIndices); 64 65 var yValuesPerColumn = ProcessMatrixForCharting(valueMissing); 70 66 PrepareChart(); 71 67 CreateSeries(yValuesPerColumn); … … 95 91 96 92 private void CreateSeries(List<List<int>> yValuesPerColumn) { 93 chart.Series.SuspendUpdates(); 97 94 //prepare series 98 95 int seriesCount = DetermineSeriesCount(yValuesPerColumn); 99 96 for (int i = 0; i < seriesCount; i++) { 100 chart.Series.Add(CreateSeriesName(i)); 101 Series series = chart.Series[CreateSeriesName(i)]; 97 Series series = new Series(CreateSeriesName(i)); 102 98 series.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn; 103 99 series.IsVisibleInLegend = false; 104 100 series["PointWidth"] = "1.0"; 105 if (i % 2 == 0) { 106 if (i == 0) //show legend for non missing values only once 107 series.IsVisibleInLegend = true; 108 series.Color = colorNonMissingVal; 109 } else { 110 if (i == 1) //show legend for missing values only once 111 series.IsVisibleInLegend = true; 112 series.Color = colorMissingVal; 113 } 101 series.IsVisibleInLegend = i < 2; //only first two series are visible, non-missing and missing values 102 series.Color = i % 2 == 0 ? colorNonMissingValue : colorMissingValue; 103 104 var values = yValuesPerColumn.Select(y => i < y.Count ? y[i] : 0).ToArray(); 105 series.Points.DataBindY(values); 106 chart.Series.Add(series); 114 107 } 115 //fill series 116 for (int i = 0; i < yValuesPerColumn.Count; i++) { 117 List<int> column = yValuesPerColumn[i]; 118 for (int j = 0; j < seriesCount; j++) { 119 if (column.Count - 1 < j) { 120 chart.Series[CreateSeriesName(j)].Points.AddY(0); 121 } else { 122 chart.Series[CreateSeriesName(j)].Points.AddY(column[j]); 123 } 124 } 125 } 108 chart.Series.ResumeUpdates(); 126 109 } 127 110 … … 136 119 #region data_preparation_for_chartseries 137 120 private int DetermineSeriesCount(List<List<int>> yValuesPerColumn) { 138 int highest = 0; 139 foreach (List<int> values in yValuesPerColumn) { 140 highest = Math.Max(values.Count, highest); 141 } 142 return highest; 121 return yValuesPerColumn.Max(values => values.Count); 143 122 } 144 123 145 private List<List<int>> ProcessMatrixForCharting(List<List<bool>> matrix, IDictionary<int, IList<int>> missingValueIndices) { 146 List<List<int>> columnsYValues = new List<List<int>>(); 147 for (int i = 0; i < matrix.Count; i++) //column 148 { 149 List<int> yValues = new List<int>(); 150 List<bool> column = matrix[i]; 124 private List<List<int>> ProcessMatrixForCharting(bool[,] matrix) { 125 var columnsYValues = new List<List<int>>(); 126 for (int column = 0; column < matrix.GetLength(1); column++) { 127 var yValues = new List<int>(); 151 128 bool missingState = false; 152 129 int valueCount = 0; 153 for (int j = 0; j < column.Count; j++) { 154 if (missingState == missingValueIndices[i].Contains(j)) { 130 131 for (int row = 0; row < matrix.GetLength(0); row++) { 132 if (missingState == matrix[row, column]) { 155 133 valueCount++; 156 134 } else { … … 165 143 yValues.Add(0); 166 144 } 167 //yValues.Reverse();168 145 columnsYValues.Add(yValues); 169 146 }
Note: See TracChangeset
for help on using the changeset viewer.