[13502] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[10913] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Drawing;
|
---|
[13502] | 25 | using System.Windows.Forms;
|
---|
[10979] | 26 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
[13502] | 27 | using HeuristicLab.Core.Views;
|
---|
| 28 | using HeuristicLab.MainForm;
|
---|
[10658] | 29 |
|
---|
| 30 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
| 31 |
|
---|
| 32 | [View("Histogram View")]
|
---|
[10877] | 33 | [Content(typeof(DataCompletenessChartContent), true)]
|
---|
[13502] | 34 | public partial class DataCompletenessView : ItemView {
|
---|
[10658] | 35 |
|
---|
[10913] | 36 | //list of columns, bool indicates wether the cell is a missing value or not
|
---|
| 37 | private List<List<bool>> matrix = new List<List<bool>>();
|
---|
[10979] | 38 | //series colors
|
---|
| 39 | private static Color colorNonMissingVal = Color.CornflowerBlue;
|
---|
| 40 | private static Color colorMissingVal = Color.Orange;
|
---|
[10913] | 41 |
|
---|
[13502] | 42 | public new DataCompletenessChartContent Content {
|
---|
[10877] | 43 | get { return (DataCompletenessChartContent)base.Content; }
|
---|
[10658] | 44 | set { base.Content = value; }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[10877] | 47 |
|
---|
[13502] | 48 | public DataCompletenessView() {
|
---|
[10877] | 49 | InitializeComponent();
|
---|
[10736] | 50 | }
|
---|
| 51 |
|
---|
[13502] | 52 | protected override void OnContentChanged() {
|
---|
[10818] | 53 | base.OnContentChanged();
|
---|
[13502] | 54 | if (Content != null) {
|
---|
[10913] | 55 | InitData();
|
---|
[10818] | 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[13502] | 59 | private void InitData() {
|
---|
[10913] | 60 | IDictionary<int, IList<int>> missingValueIndices = Content.SearchLogic.GetMissingValueIndices();
|
---|
[13502] | 61 | for (int i = 0; i < Content.SearchLogic.Columns; i++) {
|
---|
[10913] | 62 | //append column
|
---|
| 63 | List<bool> column = new List<bool>();
|
---|
[11002] | 64 | for (int j = 0; j < Content.SearchLogic.Rows; j++) {
|
---|
[10913] | 65 | column.Add(missingValueIndices[i].Contains(j));
|
---|
| 66 | }
|
---|
| 67 | matrix.Add(column);
|
---|
| 68 | }
|
---|
| 69 | List<List<int>> yValuesPerColumn = ProcessMatrixForCharting(matrix, missingValueIndices);
|
---|
[10979] | 70 | PrepareChart();
|
---|
| 71 | CreateSeries(yValuesPerColumn);
|
---|
[10913] | 72 | }
|
---|
| 73 |
|
---|
[13502] | 74 | private void PrepareChart() {
|
---|
[10979] | 75 | chart.Titles.Add("DataCompletenessChart");
|
---|
[10981] | 76 | chart.EnableDoubleClickResetsZoom = true;
|
---|
[10979] | 77 | chart.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
|
---|
| 78 | chart.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
|
---|
| 79 | chart.ChartAreas[0].AxisX.IsMarginVisible = false;
|
---|
| 80 | chart.ChartAreas[0].AxisY.IsMarginVisible = false;
|
---|
[10981] | 81 | chart.ChartAreas[0].CursorX.IsUserEnabled = true;
|
---|
| 82 | chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
|
---|
| 83 | chart.ChartAreas[0].CursorY.IsUserEnabled = true;
|
---|
| 84 | chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
|
---|
[10979] | 85 | //custom x axis label
|
---|
| 86 | double from = 0.5;
|
---|
[13502] | 87 | foreach (String columnName in Content.SearchLogic.VariableNames) {
|
---|
[10979] | 88 | double to = from + 1;
|
---|
| 89 | chart.ChartAreas[0].AxisX.CustomLabels.Add(from, to, columnName);
|
---|
| 90 | from = to;
|
---|
| 91 | }
|
---|
| 92 | //custom y axis label
|
---|
| 93 | chart.ChartAreas[0].AxisY.IsReversed = true;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[13502] | 96 | private void CreateSeries(List<List<int>> yValuesPerColumn) {
|
---|
[10913] | 97 | //prepare series
|
---|
[10979] | 98 | int seriesCount = DetermineSeriesCount(yValuesPerColumn);
|
---|
[13502] | 99 | for (int i = 0; i < seriesCount; i++) {
|
---|
[10979] | 100 | chart.Series.Add(CreateSeriesName(i));
|
---|
| 101 | Series series = chart.Series[CreateSeriesName(i)];
|
---|
| 102 | series.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn;
|
---|
| 103 | series.IsVisibleInLegend = false;
|
---|
| 104 | series["PointWidth"] = "1.0";
|
---|
[13502] | 105 | if (i % 2 == 0) {
|
---|
[10979] | 106 | if (i == 0) //show legend for non missing values only once
|
---|
| 107 | series.IsVisibleInLegend = true;
|
---|
| 108 | series.Color = colorNonMissingVal;
|
---|
[13502] | 109 | } else {
|
---|
[10979] | 110 | if (i == 1) //show legend for missing values only once
|
---|
| 111 | series.IsVisibleInLegend = true;
|
---|
| 112 | series.Color = colorMissingVal;
|
---|
| 113 | }
|
---|
[10913] | 114 | }
|
---|
| 115 | //fill series
|
---|
[13502] | 116 | for (int i = 0; i < yValuesPerColumn.Count; i++) {
|
---|
[10913] | 117 | List<int> column = yValuesPerColumn[i];
|
---|
| 118 | for (int j = 0; j < seriesCount; j++) {
|
---|
| 119 | if (column.Count - 1 < j) {
|
---|
[10979] | 120 | chart.Series[CreateSeriesName(j)].Points.AddY(0);
|
---|
[10913] | 121 | } else {
|
---|
[10979] | 122 | chart.Series[CreateSeriesName(j)].Points.AddY(column[j]);
|
---|
[10913] | 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[13502] | 128 | private String CreateSeriesName(int index) {
|
---|
[10979] | 129 | if (index == 0)
|
---|
| 130 | return "non-missing value";
|
---|
| 131 | else if (index == 1)
|
---|
| 132 | return "missing value";
|
---|
| 133 | return "series" + index;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | #region data_preparation_for_chartseries
|
---|
[13502] | 137 | private int DetermineSeriesCount(List<List<int>> yValuesPerColumn) {
|
---|
[10913] | 138 | int highest = 0;
|
---|
| 139 | foreach (List<int> values in yValuesPerColumn) {
|
---|
| 140 | highest = Math.Max(values.Count, highest);
|
---|
| 141 | }
|
---|
| 142 | return highest;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[13502] | 145 | private List<List<int>> ProcessMatrixForCharting(List<List<bool>> matrix, IDictionary<int, IList<int>> missingValueIndices) {
|
---|
[10913] | 146 | List<List<int>> columnsYValues = new List<List<int>>();
|
---|
[13502] | 147 | for (int i = 0; i < matrix.Count; i++) //column
|
---|
[10913] | 148 | {
|
---|
| 149 | List<int> yValues = new List<int>();
|
---|
| 150 | List<bool> column = matrix[i];
|
---|
| 151 | bool missingState = false;
|
---|
| 152 | int valueCount = 0;
|
---|
[13502] | 153 | for (int j = 0; j < column.Count; j++) {
|
---|
| 154 | if (missingState == missingValueIndices[i].Contains(j)) {
|
---|
[10913] | 155 | valueCount++;
|
---|
[13502] | 156 | } else {
|
---|
[10913] | 157 | yValues.Add(valueCount);
|
---|
| 158 | valueCount = 1;
|
---|
| 159 | missingState = !missingState;
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 | yValues.Add(valueCount);
|
---|
[10979] | 163 | if (missingState) //handle last missing
|
---|
| 164 | {
|
---|
| 165 | yValues.Add(0);
|
---|
| 166 | }
|
---|
| 167 | //yValues.Reverse();
|
---|
[10913] | 168 | columnsYValues.Add(yValues);
|
---|
| 169 | }
|
---|
| 170 | return columnsYValues;
|
---|
| 171 | }
|
---|
[10979] | 172 | #endregion
|
---|
[10658] | 173 | }
|
---|
| 174 | }
|
---|