[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;
|
---|
[10979] | 9 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
[10658] | 10 |
|
---|
| 11 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
| 12 |
|
---|
| 13 | [View("Histogram View")]
|
---|
[10877] | 14 | [Content(typeof(DataCompletenessChartContent), true)]
|
---|
[10913] | 15 | public partial class DataCompletenessView : ItemView
|
---|
| 16 | {
|
---|
[10658] | 17 |
|
---|
[10913] | 18 | //list of columns, bool indicates wether the cell is a missing value or not
|
---|
| 19 | private List<List<bool>> matrix = new List<List<bool>>();
|
---|
[10979] | 20 | //series colors
|
---|
| 21 | private static Color colorNonMissingVal = Color.CornflowerBlue;
|
---|
| 22 | private static Color colorMissingVal = Color.Orange;
|
---|
[10913] | 23 |
|
---|
[10877] | 24 | public new DataCompletenessChartContent Content
|
---|
| 25 | {
|
---|
| 26 | get { return (DataCompletenessChartContent)base.Content; }
|
---|
[10658] | 27 | set { base.Content = value; }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
[10877] | 30 |
|
---|
| 31 | public DataCompletenessView()
|
---|
| 32 | {
|
---|
| 33 | InitializeComponent();
|
---|
[10736] | 34 | }
|
---|
| 35 |
|
---|
[10818] | 36 | protected override void OnContentChanged()
|
---|
| 37 | {
|
---|
| 38 | base.OnContentChanged();
|
---|
| 39 | if (Content != null)
|
---|
| 40 | {
|
---|
[10913] | 41 | InitData();
|
---|
[10818] | 42 | }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[10913] | 45 | private void InitData()
|
---|
| 46 | {
|
---|
| 47 | IDictionary<int, IList<int>> missingValueIndices = Content.SearchLogic.GetMissingValueIndices();
|
---|
| 48 | for (int i = 0; i < Content.DataGridLogic.Columns; i++)
|
---|
| 49 | {
|
---|
| 50 | //append column
|
---|
| 51 | List<bool> column = new List<bool>();
|
---|
| 52 | for (int j=0; j < Content.DataGridLogic.Rows; j++) {
|
---|
| 53 | column.Add(missingValueIndices[i].Contains(j));
|
---|
| 54 | }
|
---|
| 55 | matrix.Add(column);
|
---|
| 56 | }
|
---|
| 57 | List<List<int>> yValuesPerColumn = ProcessMatrixForCharting(matrix, missingValueIndices);
|
---|
[10979] | 58 | PrepareChart();
|
---|
| 59 | CreateSeries(yValuesPerColumn);
|
---|
[10913] | 60 | }
|
---|
| 61 |
|
---|
[10979] | 62 | private void PrepareChart()
|
---|
[10913] | 63 | {
|
---|
[10979] | 64 | chart.Titles.Add("DataCompletenessChart");
|
---|
[10981] | 65 | chart.EnableDoubleClickResetsZoom = true;
|
---|
[10979] | 66 | chart.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
|
---|
| 67 | chart.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
|
---|
| 68 | chart.ChartAreas[0].AxisX.IsMarginVisible = false;
|
---|
| 69 | chart.ChartAreas[0].AxisY.IsMarginVisible = false;
|
---|
[10981] | 70 | chart.ChartAreas[0].CursorX.IsUserEnabled = true;
|
---|
| 71 | chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
|
---|
| 72 | chart.ChartAreas[0].CursorY.IsUserEnabled = true;
|
---|
| 73 | chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
|
---|
[10979] | 74 | //custom x axis label
|
---|
| 75 | double from = 0.5;
|
---|
| 76 | foreach (String columnName in Content.DataGridLogic.ColumnNames)
|
---|
| 77 | {
|
---|
| 78 | double to = from + 1;
|
---|
| 79 | chart.ChartAreas[0].AxisX.CustomLabels.Add(from, to, columnName);
|
---|
| 80 | from = to;
|
---|
| 81 | }
|
---|
| 82 | //custom y axis label
|
---|
| 83 | chart.ChartAreas[0].AxisY.IsReversed = true;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | private void CreateSeries(List<List<int>> yValuesPerColumn)
|
---|
| 87 | {
|
---|
[10913] | 88 | //prepare series
|
---|
[10979] | 89 | int seriesCount = DetermineSeriesCount(yValuesPerColumn);
|
---|
[10913] | 90 | for (int i = 0; i < seriesCount; i++)
|
---|
| 91 | {
|
---|
[10979] | 92 | chart.Series.Add(CreateSeriesName(i));
|
---|
| 93 | Series series = chart.Series[CreateSeriesName(i)];
|
---|
| 94 | series.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn;
|
---|
| 95 | series.IsVisibleInLegend = false;
|
---|
| 96 | series["PointWidth"] = "1.0";
|
---|
[10913] | 97 | if (i % 2 == 0)
|
---|
[10979] | 98 | {
|
---|
| 99 | if (i == 0) //show legend for non missing values only once
|
---|
| 100 | series.IsVisibleInLegend = true;
|
---|
| 101 | series.Color = colorNonMissingVal;
|
---|
| 102 | }
|
---|
[10913] | 103 | else
|
---|
[10979] | 104 | {
|
---|
| 105 | if (i == 1) //show legend for missing values only once
|
---|
| 106 | series.IsVisibleInLegend = true;
|
---|
| 107 | series.Color = colorMissingVal;
|
---|
| 108 | }
|
---|
[10913] | 109 | }
|
---|
| 110 | //fill series
|
---|
| 111 | for (int i = 0; i < yValuesPerColumn.Count; i++)
|
---|
| 112 | {
|
---|
| 113 | List<int> column = yValuesPerColumn[i];
|
---|
| 114 | for (int j = 0; j < seriesCount; j++) {
|
---|
| 115 | if (column.Count - 1 < j) {
|
---|
[10979] | 116 | chart.Series[CreateSeriesName(j)].Points.AddY(0);
|
---|
[10913] | 117 | } else {
|
---|
[10979] | 118 | chart.Series[CreateSeriesName(j)].Points.AddY(column[j]);
|
---|
[10913] | 119 | }
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[10979] | 124 | private String CreateSeriesName(int index)
|
---|
[10913] | 125 | {
|
---|
[10979] | 126 | if (index == 0)
|
---|
| 127 | return "non-missing value";
|
---|
| 128 | else if (index == 1)
|
---|
| 129 | return "missing value";
|
---|
| 130 | return "series" + index;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | #region data_preparation_for_chartseries
|
---|
| 134 | private int DetermineSeriesCount(List<List<int>> yValuesPerColumn)
|
---|
| 135 | {
|
---|
[10913] | 136 | int highest = 0;
|
---|
| 137 | foreach (List<int> values in yValuesPerColumn) {
|
---|
| 138 | highest = Math.Max(values.Count, highest);
|
---|
| 139 | }
|
---|
| 140 | return highest;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | private List<List<int>> ProcessMatrixForCharting(List<List<bool>> matrix, IDictionary<int, IList<int>> missingValueIndices)
|
---|
| 144 | {
|
---|
| 145 | List<List<int>> columnsYValues = new List<List<int>>();
|
---|
| 146 | for (int i=0; i < matrix.Count; i++) //column
|
---|
| 147 | {
|
---|
| 148 | List<int> yValues = new List<int>();
|
---|
| 149 | List<bool> column = matrix[i];
|
---|
| 150 | bool missingState = false;
|
---|
| 151 | int valueCount = 0;
|
---|
| 152 | for (int j = 0; j < column.Count; j++ ) {
|
---|
| 153 | if (missingState == missingValueIndices[i].Contains(j))
|
---|
| 154 | {
|
---|
| 155 | valueCount++;
|
---|
| 156 | }
|
---|
| 157 | else
|
---|
| 158 | {
|
---|
| 159 | yValues.Add(valueCount);
|
---|
| 160 | valueCount = 1;
|
---|
| 161 | missingState = !missingState;
|
---|
| 162 | }
|
---|
| 163 | }
|
---|
| 164 | yValues.Add(valueCount);
|
---|
[10979] | 165 | if (missingState) //handle last missing
|
---|
| 166 | {
|
---|
| 167 | yValues.Add(0);
|
---|
| 168 | }
|
---|
| 169 | //yValues.Reverse();
|
---|
[10913] | 170 | columnsYValues.Add(yValues);
|
---|
| 171 | }
|
---|
| 172 | return columnsYValues;
|
---|
| 173 | }
|
---|
[10979] | 174 | #endregion
|
---|
[10658] | 175 | }
|
---|
| 176 | }
|
---|