[10736] | 1 | using System;
|
---|
| 2 | using System.Windows.Forms;
|
---|
[10658] | 3 | using HeuristicLab.Analysis;
|
---|
| 4 | using HeuristicLab.MainForm;
|
---|
[10877] | 5 | using HeuristicLab.Core.Views;
|
---|
[10913] | 6 | using System.Collections.Generic;
|
---|
| 7 | using HeuristicLab.DataPreprocessing.Implementations;
|
---|
| 8 | using System.Drawing;
|
---|
[10658] | 9 |
|
---|
| 10 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
| 11 |
|
---|
| 12 | [View("Histogram View")]
|
---|
[10877] | 13 | [Content(typeof(DataCompletenessChartContent), true)]
|
---|
[10913] | 14 | public partial class DataCompletenessView : ItemView
|
---|
| 15 | {
|
---|
[10658] | 16 |
|
---|
[10877] | 17 | protected DataRowVisualProperties.DataRowChartType chartType;
|
---|
| 18 | protected string chartTitle;
|
---|
[10658] | 19 |
|
---|
[10877] | 20 | private const string DEFAULT_CHART_TITLE = "DataCompletenessChart";
|
---|
[10658] | 21 |
|
---|
[10913] | 22 | //list of columns, bool indicates wether the cell is a missing value or not
|
---|
| 23 | private List<List<bool>> matrix = new List<List<bool>>();
|
---|
| 24 |
|
---|
[10877] | 25 | public new DataCompletenessChartContent Content
|
---|
| 26 | {
|
---|
| 27 | get { return (DataCompletenessChartContent)base.Content; }
|
---|
[10658] | 28 | set { base.Content = value; }
|
---|
| 29 | }
|
---|
| 30 |
|
---|
[10877] | 31 |
|
---|
| 32 | public DataCompletenessView()
|
---|
| 33 | {
|
---|
| 34 | InitializeComponent();
|
---|
[10913] | 35 | chartType = DataRowVisualProperties.DataRowChartType.Bars;
|
---|
[10877] | 36 | chartTitle = DEFAULT_CHART_TITLE;
|
---|
[10736] | 37 | }
|
---|
| 38 |
|
---|
[10818] | 39 | protected override void OnContentChanged()
|
---|
| 40 | {
|
---|
| 41 | base.OnContentChanged();
|
---|
| 42 | if (Content != null)
|
---|
| 43 | {
|
---|
[10913] | 44 | InitData();
|
---|
[10818] | 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[10913] | 48 | private void InitData()
|
---|
| 49 | {
|
---|
| 50 | IDictionary<int, IList<int>> missingValueIndices = Content.SearchLogic.GetMissingValueIndices();
|
---|
| 51 | for (int i = 0; i < Content.DataGridLogic.Columns; i++)
|
---|
| 52 | {
|
---|
| 53 | //append column
|
---|
| 54 | List<bool> column = new List<bool>();
|
---|
| 55 | for (int j=0; j < Content.DataGridLogic.Rows; j++) {
|
---|
| 56 | column.Add(missingValueIndices[i].Contains(j));
|
---|
| 57 | }
|
---|
| 58 | matrix.Add(column);
|
---|
| 59 | }
|
---|
| 60 | List<List<int>> yValuesPerColumn = ProcessMatrixForCharting(matrix, missingValueIndices);
|
---|
| 61 | createSeries(yValuesPerColumn);
|
---|
| 62 | //CreateChart();
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | private void createSeries(List<List<int>> yValuesPerColumn)
|
---|
| 66 | {
|
---|
| 67 | //prepare series
|
---|
| 68 | int seriesCount = determineSeriesCount(yValuesPerColumn);
|
---|
| 69 | for (int i = 0; i < seriesCount; i++)
|
---|
| 70 | {
|
---|
| 71 | chart.Series.Add("series"+i);
|
---|
| 72 | chart.Series["series"+i].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn;
|
---|
| 73 | if (i % 2 == 0)
|
---|
| 74 | chart.Series["series" + i].Color = Color.Blue;
|
---|
| 75 | else
|
---|
| 76 | chart.Series["series" + i].Color = Color.White;
|
---|
| 77 | }
|
---|
| 78 | //fill series
|
---|
| 79 | for (int i = 0; i < yValuesPerColumn.Count; i++)
|
---|
| 80 | {
|
---|
| 81 | List<int> column = yValuesPerColumn[i];
|
---|
| 82 | for (int j = 0; j < seriesCount; j++) {
|
---|
| 83 | if (column.Count - 1 < j) {
|
---|
| 84 | chart.Series["series"+j].Points.AddY(0);
|
---|
| 85 | } else {
|
---|
| 86 | chart.Series["series" + j].Points.AddY(column[j]);
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | private int determineSeriesCount(List<List<int>> yValuesPerColumn)
|
---|
| 93 | {
|
---|
| 94 | int highest = 0;
|
---|
| 95 | foreach (List<int> values in yValuesPerColumn) {
|
---|
| 96 | highest = Math.Max(values.Count, highest);
|
---|
| 97 | }
|
---|
| 98 | return highest;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | private List<List<int>> ProcessMatrixForCharting(List<List<bool>> matrix, IDictionary<int, IList<int>> missingValueIndices)
|
---|
| 102 | {
|
---|
| 103 | List<List<int>> columnsYValues = new List<List<int>>();
|
---|
| 104 | for (int i=0; i < matrix.Count; i++) //column
|
---|
| 105 | {
|
---|
| 106 | List<int> yValues = new List<int>();
|
---|
| 107 | List<bool> column = matrix[i];
|
---|
| 108 | bool missingState = false;
|
---|
| 109 | int valueCount = 0;
|
---|
| 110 | for (int j = 0; j < column.Count; j++ ) {
|
---|
| 111 | if (missingState == missingValueIndices[i].Contains(j))
|
---|
| 112 | {
|
---|
| 113 | valueCount++;
|
---|
| 114 | }
|
---|
| 115 | else
|
---|
| 116 | {
|
---|
| 117 | yValues.Add(valueCount);
|
---|
| 118 | valueCount = 1;
|
---|
| 119 | missingState = !missingState;
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 | yValues.Add(valueCount);
|
---|
| 123 | /*
|
---|
| 124 | List<int> yValues = new List<int>();
|
---|
| 125 | bool missingChanged = true;
|
---|
| 126 | while ()
|
---|
| 127 | * */
|
---|
| 128 | columnsYValues.Add(yValues);
|
---|
| 129 | }
|
---|
| 130 | return columnsYValues;
|
---|
| 131 | }
|
---|
| 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 |
|
---|
[10658] | 166 | }
|
---|
| 167 | }
|
---|