[15973] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2018 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;
|
---|
[15973] | 25 | using System.Linq;
|
---|
[10979] | 26 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
[15973] | 27 | using HeuristicLab.Core.Views;
|
---|
| 28 | using HeuristicLab.MainForm;
|
---|
[10658] | 29 |
|
---|
| 30 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
| 31 | [View("Histogram View")]
|
---|
[10877] | 32 | [Content(typeof(DataCompletenessChartContent), true)]
|
---|
[15973] | 33 | public partial class DataCompletenessView : ItemView {
|
---|
[10979] | 34 | //series colors
|
---|
[15973] | 35 | private static readonly Color colorNonMissingValue = Color.CornflowerBlue;
|
---|
| 36 | private static readonly Color colorMissingValue = Color.Orange;
|
---|
[10913] | 37 |
|
---|
[15973] | 38 | public new DataCompletenessChartContent Content {
|
---|
[10877] | 39 | get { return (DataCompletenessChartContent)base.Content; }
|
---|
[10658] | 40 | set { base.Content = value; }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[15973] | 43 | public DataCompletenessView() {
|
---|
[10877] | 44 | InitializeComponent();
|
---|
[10736] | 45 | }
|
---|
| 46 |
|
---|
[15973] | 47 | protected override void OnContentChanged() {
|
---|
[10818] | 48 | base.OnContentChanged();
|
---|
[15973] | 49 | if (Content == null) return;
|
---|
| 50 | InitData();
|
---|
[10818] | 51 | }
|
---|
| 52 |
|
---|
[15973] | 53 | private void InitData() {
|
---|
| 54 | bool[,] valueMissing = new bool[Content.PreprocessingData.Rows, Content.PreprocessingData.Columns];
|
---|
| 55 | for (int row = 0; row < Content.PreprocessingData.Rows; row++) {
|
---|
| 56 | for (int column = 0; column < Content.PreprocessingData.Columns; column++)
|
---|
| 57 | valueMissing[row, column] = Content.PreprocessingData.IsCellEmpty(column, row);
|
---|
[10913] | 58 | }
|
---|
[15973] | 59 |
|
---|
| 60 | var yValuesPerColumn = ProcessMatrixForCharting(valueMissing);
|
---|
[10979] | 61 | PrepareChart();
|
---|
| 62 | CreateSeries(yValuesPerColumn);
|
---|
[10913] | 63 | }
|
---|
| 64 |
|
---|
[15973] | 65 | private void PrepareChart() {
|
---|
[10981] | 66 | chart.EnableDoubleClickResetsZoom = true;
|
---|
[10979] | 67 | chart.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
|
---|
| 68 | chart.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
|
---|
| 69 | chart.ChartAreas[0].AxisX.IsMarginVisible = false;
|
---|
| 70 | chart.ChartAreas[0].AxisY.IsMarginVisible = false;
|
---|
[10981] | 71 | chart.ChartAreas[0].CursorX.IsUserEnabled = true;
|
---|
| 72 | chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
|
---|
| 73 | chart.ChartAreas[0].CursorY.IsUserEnabled = true;
|
---|
| 74 | chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
|
---|
[10979] | 75 | //custom x axis label
|
---|
| 76 | double from = 0.5;
|
---|
[15973] | 77 | foreach (String columnName in Content.PreprocessingData.VariableNames) {
|
---|
[10979] | 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 |
|
---|
[15973] | 86 | private void CreateSeries(List<List<int>> yValuesPerColumn) {
|
---|
| 87 | chart.Series.SuspendUpdates();
|
---|
[10913] | 88 | //prepare series
|
---|
[10979] | 89 | int seriesCount = DetermineSeriesCount(yValuesPerColumn);
|
---|
[15973] | 90 | for (int i = 0; i < seriesCount; i++) {
|
---|
| 91 | Series series = new Series(CreateSeriesName(i));
|
---|
[10979] | 92 | series.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn;
|
---|
| 93 | series.IsVisibleInLegend = false;
|
---|
| 94 | series["PointWidth"] = "1.0";
|
---|
[15973] | 95 | series.IsVisibleInLegend = i < 2; //only first two series are visible, non-missing and missing values
|
---|
| 96 | series.Color = i % 2 == 0 ? colorNonMissingValue : colorMissingValue;
|
---|
| 97 |
|
---|
| 98 | var values = yValuesPerColumn.Select(y => i < y.Count ? y[i] : 0).ToArray();
|
---|
| 99 | series.Points.DataBindY(values);
|
---|
| 100 | chart.Series.Add(series);
|
---|
[10913] | 101 | }
|
---|
[15973] | 102 | chart.Series.ResumeUpdates();
|
---|
[10913] | 103 | }
|
---|
| 104 |
|
---|
[15973] | 105 | private String CreateSeriesName(int index) {
|
---|
[10979] | 106 | if (index == 0)
|
---|
| 107 | return "non-missing value";
|
---|
| 108 | else if (index == 1)
|
---|
| 109 | return "missing value";
|
---|
| 110 | return "series" + index;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | #region data_preparation_for_chartseries
|
---|
[15973] | 114 | private int DetermineSeriesCount(List<List<int>> yValuesPerColumn) {
|
---|
| 115 | return yValuesPerColumn.Max(values => values.Count);
|
---|
[10913] | 116 | }
|
---|
| 117 |
|
---|
[15973] | 118 | private List<List<int>> ProcessMatrixForCharting(bool[,] matrix) {
|
---|
| 119 | var columnsYValues = new List<List<int>>();
|
---|
| 120 | for (int column = 0; column < matrix.GetLength(1); column++) {
|
---|
| 121 | var yValues = new List<int>();
|
---|
[10913] | 122 | bool missingState = false;
|
---|
| 123 | int valueCount = 0;
|
---|
[15973] | 124 |
|
---|
| 125 | for (int row = 0; row < matrix.GetLength(0); row++) {
|
---|
| 126 | if (missingState == matrix[row, column]) {
|
---|
[10913] | 127 | valueCount++;
|
---|
[15973] | 128 | } else {
|
---|
[10913] | 129 | yValues.Add(valueCount);
|
---|
| 130 | valueCount = 1;
|
---|
| 131 | missingState = !missingState;
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 | yValues.Add(valueCount);
|
---|
[10979] | 135 | if (missingState) //handle last missing
|
---|
| 136 | {
|
---|
| 137 | yValues.Add(0);
|
---|
| 138 | }
|
---|
[10913] | 139 | columnsYValues.Add(yValues);
|
---|
| 140 | }
|
---|
| 141 | return columnsYValues;
|
---|
| 142 | }
|
---|
[10979] | 143 | #endregion
|
---|
[10658] | 144 | }
|
---|
| 145 | }
|
---|