Changeset 10979 for branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/DataCompletenessView.cs
- Timestamp:
- 06/11/14 13:18:37 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/DataCompletenessView.cs
r10913 r10979 7 7 using HeuristicLab.DataPreprocessing.Implementations; 8 8 using System.Drawing; 9 using System.Windows.Forms.DataVisualization.Charting; 9 10 10 11 namespace HeuristicLab.DataPreprocessing.Views { … … 15 16 { 16 17 17 protected DataRowVisualProperties.DataRowChartType chartType;18 protected string chartTitle;19 20 private const string DEFAULT_CHART_TITLE = "DataCompletenessChart";21 22 18 //list of columns, bool indicates wether the cell is a missing value or not 23 19 private List<List<bool>> matrix = new List<List<bool>>(); 20 //series colors 21 private static Color colorNonMissingVal = Color.CornflowerBlue; 22 private static Color colorMissingVal = Color.Orange; 24 23 25 24 public new DataCompletenessChartContent Content … … 33 32 { 34 33 InitializeComponent(); 35 chartType = DataRowVisualProperties.DataRowChartType.Bars;36 chartTitle = DEFAULT_CHART_TITLE;37 34 } 38 35 … … 42 39 if (Content != null) 43 40 { 41 //chart.PrePaint += chart_PrePaint; 42 //chart.CustomizeLegend += chart_CustomizeLegend; 44 43 InitData(); 45 44 } 46 45 } 46 47 48 /* 49 void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) 50 { 51 foreach (LegendItem li in e.LegendItems) 52 { 53 int label; 54 int.TryParse(li.Cells[0].ToString(), out label); 55 56 li.Cells[0].Text = "Banane"; 57 //li.Cells[0].Text = (label - Content.DataGridLogic.Rows).ToString(); 58 } 59 }*/ 47 60 48 61 private void InitData() … … 59 72 } 60 73 List<List<int>> yValuesPerColumn = ProcessMatrixForCharting(matrix, missingValueIndices); 61 createSeries(yValuesPerColumn);62 //CreateChart();74 PrepareChart(); 75 CreateSeries(yValuesPerColumn); 63 76 } 64 77 65 private void createSeries(List<List<int>> yValuesPerColumn) 78 private void PrepareChart() 79 { 80 chart.Titles.Add("DataCompletenessChart"); 81 chart.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0; 82 chart.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0; 83 chart.ChartAreas[0].AxisX.IsMarginVisible = false; 84 chart.ChartAreas[0].AxisY.IsMarginVisible = false; 85 //custom x axis label 86 double from = 0.5; 87 foreach (String columnName in Content.DataGridLogic.ColumnNames) 88 { 89 double to = from + 1; 90 chart.ChartAreas[0].AxisX.CustomLabels.Add(from, to, columnName); 91 from = to; 92 } 93 //custom y axis label 94 chart.ChartAreas[0].AxisY.IsReversed = true; 95 } 96 97 98 99 private void CreateSeries(List<List<int>> yValuesPerColumn) 66 100 { 67 101 //prepare series 68 int seriesCount = determineSeriesCount(yValuesPerColumn);102 int seriesCount = DetermineSeriesCount(yValuesPerColumn); 69 103 for (int i = 0; i < seriesCount; i++) 70 104 { 71 chart.Series.Add("series"+i); 72 chart.Series["series"+i].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn; 105 chart.Series.Add(CreateSeriesName(i)); 106 Series series = chart.Series[CreateSeriesName(i)]; 107 series.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn; 108 series.IsVisibleInLegend = false; 109 series["PointWidth"] = "1.0"; 73 110 if (i % 2 == 0) 74 chart.Series["series" + i].Color = Color.Blue; 111 { 112 if (i == 0) //show legend for non missing values only once 113 series.IsVisibleInLegend = true; 114 series.Color = colorNonMissingVal; 115 } 75 116 else 76 chart.Series["series" + i].Color = Color.White; 117 { 118 if (i == 1) //show legend for missing values only once 119 series.IsVisibleInLegend = true; 120 series.Color = colorMissingVal; 121 } 77 122 } 78 123 //fill series … … 82 127 for (int j = 0; j < seriesCount; j++) { 83 128 if (column.Count - 1 < j) { 84 chart.Series[ "series"+j].Points.AddY(0);129 chart.Series[CreateSeriesName(j)].Points.AddY(0); 85 130 } else { 86 chart.Series[ "series" + j].Points.AddY(column[j]);131 chart.Series[CreateSeriesName(j)].Points.AddY(column[j]); 87 132 } 88 133 } … … 90 135 } 91 136 92 private int determineSeriesCount(List<List<int>> yValuesPerColumn) 137 private String CreateSeriesName(int index) 138 { 139 if (index == 0) 140 return "non-missing value"; 141 else if (index == 1) 142 return "missing value"; 143 return "series" + index; 144 } 145 146 #region data_preparation_for_chartseries 147 private int DetermineSeriesCount(List<List<int>> yValuesPerColumn) 93 148 { 94 149 int highest = 0; … … 121 176 } 122 177 yValues.Add(valueCount); 123 /*124 List<int> yValues = new List<int>();125 bool missingChanged = true;126 while ()127 * */178 if (missingState) //handle last missing 179 { 180 yValues.Add(0); 181 } 182 //yValues.Reverse(); 128 183 columnsYValues.Add(yValues); 129 184 } 130 185 return columnsYValues; 131 186 } 132 133 const String missingValue = "Red"; 134 const String existingValue = "DarkBlue"; 135 136 137 private void CreateChart() 138 { 139 object[] temp = new[] { "1", "50" }; 140 object[] temp2 = new[] { "50", "1000" }; 141 chart.Series.Add(missingValue); 142 chart.Series.Add(existingValue); 143 144 for(int i=0; i < matrix.Count; i++) { 145 List<bool> column = matrix[i]; 146 for (int j = 0; j < column.Count; j++ ) 147 { 148 chart.Series[missingValue].Points.AddXY(i, temp); 149 chart.Series[existingValue].Points.AddXY(i, temp2); 150 chart.Series[missingValue].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedBar; 151 chart.Series[existingValue].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedBar; 152 } 153 } 154 } 155 156 /* 157 private DataRow columnToDataRow(List<bool> column, int i) 158 { 159 DataRow row = new DataRow("row"+i); 160 foreach (bool missing in column) { 161 row.Values.Add(missing? 1 : 0); 162 } 163 return row; 164 }*/ 165 187 #endregion 166 188 } 167 189 }
Note: See TracChangeset
for help on using the changeset viewer.