#region License Information /* HeuristicLab * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms.DataVisualization.Charting; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; namespace HeuristicLab.DataPreprocessing.Views { [View("Histogram View")] [Content(typeof(DataCompletenessChartContent), true)] public partial class DataCompletenessView : ItemView { //series colors private static readonly Color colorNonMissingValue = Color.CornflowerBlue; private static readonly Color colorMissingValue = Color.Orange; private bool[,] valueMissing; public new DataCompletenessChartContent Content { get { return (DataCompletenessChartContent)base.Content; } set { base.Content = value; } } public DataCompletenessView() { InitializeComponent(); } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) return; InitData(); } private void InitData() { valueMissing = new bool[Content.PreprocessingData.Rows, Content.PreprocessingData.Columns]; for (int row = 0; row < Content.PreprocessingData.Rows; row++) { for (int column = 0; column < Content.PreprocessingData.Columns; column++) valueMissing[row, column] = Content.PreprocessingData.IsCellEmpty(column, row); } var yValuesPerColumn = ProcessMatrixForCharting(valueMissing); } #region data_preparation_for_chartseries private int DetermineSeriesCount(List> yValuesPerColumn) { return yValuesPerColumn.Max(values => values.Count); } private List> ProcessMatrixForCharting(bool[,] matrix) { var columnsYValues = new List>(); for (int column = 0; column < matrix.GetLength(1); column++) { var yValues = new List(); bool missingState = false; int valueCount = 0; for (int row = 0; row < matrix.GetLength(0); row++) { if (missingState == matrix[row, column]) { valueCount++; } else { yValues.Add(valueCount); valueCount = 1; missingState = !missingState; } } yValues.Add(valueCount); if (missingState) //handle last missing { yValues.Add(0); } columnsYValues.Add(yValues); } return columnsYValues; } #endregion private void pictureBox_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { var m = valueMissing; var g = e.Graphics; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; g.Clear(colorNonMissingValue); // TODO consider cliprectangle using (var bm = new Bitmap(m.GetLength(0), m.GetLength(1))) { for (int r = 0; r < m.GetLength(0); r++) for (int c = 0; c < m.GetLength(1); c++) { if (m[r, c]) bm.SetPixel(r, c, colorMissingValue); } g.DrawImage(bm, 0, 0, pictureBox.Width, pictureBox.Height); } } private void toolStrip2_ItemClicked(object sender, System.Windows.Forms.ToolStripItemClickedEventArgs e) { } private void pictureBox_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { toolTip.SetToolTip(pictureBox, "TODO: show variable") } } }