Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/EnhancedStringConvertibleMatrixView.cs @ 8833

Last change on this file since 8833 was 8833, checked in by sforsten, 11 years ago

#1292:

  • removed combo box in TimeframeCorrelationView and added a textbox instead
  • caches are directly in (Timeframe-)FeatureCorrelationView
  • caches use Tuple<> instead of nested dictionaries
  • a control EnhancedStringConvertibleMatrix inherits from StringConvertibleMatrixView to reduce code duplication
  • add interface IDependencyCalculator to several calculators
  • fixed bug: a previous started calculation is cancelled, if a new calculation shall be started and the values are already in the cache
  • fixed bug: if the content is changed, the calculation is cancelled

HeatMap is still used for the dependency representation, because a class is needed which implements IStringConvertibleMatrix and it has a maximum and minimum value.

File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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;
27using HeuristicLab.Analysis;
28using HeuristicLab.Common;
29using HeuristicLab.Data.Views;
30
31namespace HeuristicLab.Problems.DataAnalysis.Views {
32  public partial class EnhancedStringConvertibleMatrixView : StringConvertibleMatrixView {
33
34    protected IEnumerable<bool> columnVisibility, rowVisibility;
35
36    // sets the visibility of its columns for the next time it is updated
37    public IEnumerable<bool> ColumnVisibility { set { columnVisibility = value; } }
38    // sets the visibility of its rows for the next time it is updated
39    public IEnumerable<bool> RowVisibility { set { rowVisibility = value; } }
40
41    public new HeatMap Content {
42      get { return (HeatMap)base.Content; }
43      set { base.Content = value; }
44    }
45
46    public EnhancedStringConvertibleMatrixView() {
47      InitializeComponent();
48    }
49
50    public void ResetVisibility() {
51      columnVisibility = null;
52      rowVisibility = null;
53    }
54
55    protected override void UpdateColumnHeaders() {
56      base.UpdateColumnHeaders();
57      if (columnVisibility != null && Content != null && columnVisibility.Count() == dataGridView.ColumnCount) {
58        int i = 0;
59        foreach (var visibility in columnVisibility) {
60          dataGridView.Columns[i].Visible = visibility;
61          i++;
62        }
63      }
64    }
65    protected override void UpdateRowHeaders() {
66      base.UpdateRowHeaders();
67      if (rowVisibility != null && Content != null && rowVisibility.Count() == dataGridView.RowCount) {
68        int i = 0;
69        foreach (var visibility in rowVisibility) {
70          dataGridView.Rows[i].Visible = visibility;
71          i++;
72        }
73      }
74    }
75
76    protected virtual void ShowHideRows_Click(object sender, EventArgs e) {
77      var dialog = new StringConvertibleMatrixRowVisibilityDialog(this.dataGridView.Rows.Cast<DataGridViewRow>());
78      dialog.ShowDialog();
79      rowVisibility = dialog.Visibility;
80    }
81
82    protected override void ShowHideColumns_Click(object sender, EventArgs e) {
83      var dialog = new StringConvertibleMatrixColumnVisibilityDialog(this.dataGridView.Columns.Cast<DataGridViewColumn>());
84      dialog.ShowDialog();
85      columnVisibility = dialog.Visibility;
86    }
87
88    protected void dataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) {
89      if (Content == null) return;
90      if (e.RowIndex < 0) return;
91      if (e.ColumnIndex < 0) return;
92      if (e.State.HasFlag(DataGridViewElementStates.Selected)) return;
93      if (!e.PaintParts.HasFlag(DataGridViewPaintParts.Background)) return;
94
95      int rowIndex = virtualRowIndices[e.RowIndex];
96      Color backColor = GetDataPointColor(Content[rowIndex, e.ColumnIndex], Content.Minimum, Content.Maximum);
97      using (Brush backColorBrush = new SolidBrush(backColor)) {
98        e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
99      }
100      e.PaintContent(e.CellBounds);
101      e.Handled = true;
102    }
103
104    protected virtual Color GetDataPointColor(double value, double min, double max) {
105      if (double.IsNaN(value)) {
106        return Color.DarkGray;
107      }
108      IList<Color> colors = ColorGradient.Colors;
109      int index = (int)((colors.Count - 1) * (value - min) / (max - min));
110      if (index >= colors.Count) index = colors.Count - 1;
111      if (index < 0) index = 0;
112      return colors[index];
113    }
114  }
115}
Note: See TracBrowser for help on using the repository browser.