Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2922-DataCompletenessChartPerf/HeuristicLab.DataPreprocessing.Views/3.4/DataCompletenessView.cs @ 16824

Last change on this file since 16824 was 15942, checked in by gkronber, 7 years ago

#2922 changed DataCompletenessView to use a simple bitmap instead of the ChartControl.

File size: 4.2 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Drawing;
25using System.Linq;
26using System.Windows.Forms.DataVisualization.Charting;
27using HeuristicLab.Core.Views;
28using HeuristicLab.MainForm;
29
30namespace HeuristicLab.DataPreprocessing.Views {
31  [View("Histogram View")]
32  [Content(typeof(DataCompletenessChartContent), true)]
33  public partial class DataCompletenessView : ItemView {
34    //series colors
35    private static readonly Color colorNonMissingValue = Color.CornflowerBlue;
36    private static readonly Color colorMissingValue = Color.Orange;
37    private bool[,] valueMissing;
38
39    public new DataCompletenessChartContent Content {
40      get { return (DataCompletenessChartContent)base.Content; }
41      set { base.Content = value; }
42    }
43
44    public DataCompletenessView() {
45      InitializeComponent();
46    }
47
48    protected override void OnContentChanged() {
49      base.OnContentChanged();
50      if (Content == null) return;
51      InitData();
52    }
53
54    private void InitData() {
55      valueMissing = new bool[Content.PreprocessingData.Rows, Content.PreprocessingData.Columns];
56      for (int row = 0; row < Content.PreprocessingData.Rows; row++) {
57        for (int column = 0; column < Content.PreprocessingData.Columns; column++)
58          valueMissing[row, column] = Content.PreprocessingData.IsCellEmpty(column, row);
59      }
60
61      var yValuesPerColumn = ProcessMatrixForCharting(valueMissing);
62    }
63
64
65
66    #region data_preparation_for_chartseries
67    private int DetermineSeriesCount(List<List<int>> yValuesPerColumn) {
68      return yValuesPerColumn.Max(values => values.Count);
69    }
70
71    private List<List<int>> ProcessMatrixForCharting(bool[,] matrix) {
72      var columnsYValues = new List<List<int>>();
73      for (int column = 0; column < matrix.GetLength(1); column++) {
74        var yValues = new List<int>();
75        bool missingState = false;
76        int valueCount = 0;
77
78        for (int row = 0; row < matrix.GetLength(0); row++) {
79          if (missingState == matrix[row, column]) {
80            valueCount++;
81          } else {
82            yValues.Add(valueCount);
83            valueCount = 1;
84            missingState = !missingState;
85          }
86        }
87        yValues.Add(valueCount);
88        if (missingState) //handle last missing
89        {
90          yValues.Add(0);
91        }
92        columnsYValues.Add(yValues);
93      }
94      return columnsYValues;
95    }
96    #endregion
97
98    private void pictureBox_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {
99      var m = valueMissing;
100      var g = e.Graphics;
101      g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
102      g.Clear(colorNonMissingValue);
103      // TODO consider cliprectangle
104      using (var bm = new Bitmap(m.GetLength(0), m.GetLength(1))) {
105        for (int r = 0; r < m.GetLength(0); r++)
106          for (int c = 0; c < m.GetLength(1); c++) {
107            if (m[r, c]) bm.SetPixel(r, c, colorMissingValue);
108          }
109        g.DrawImage(bm, 0, 0, pictureBox.Width, pictureBox.Height);
110      }
111    }
112
113    private void toolStrip2_ItemClicked(object sender, System.Windows.Forms.ToolStripItemClickedEventArgs e) {
114
115    }
116
117    private void pictureBox_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
118      toolTip.SetToolTip(pictureBox, "TODO: show variable")
119    }
120  }
121}
Note: See TracBrowser for help on using the repository browser.