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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Linq;
|
---|
26 | using System.Windows.Forms;
|
---|
27 | using HeuristicLab.Common;
|
---|
28 | using HeuristicLab.Data;
|
---|
29 | using HeuristicLab.Data.Views;
|
---|
30 |
|
---|
31 | namespace 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 double Maximum { get; set; }
|
---|
42 | public double Minimum { get; set; }
|
---|
43 |
|
---|
44 | public new DoubleMatrix Content {
|
---|
45 | get { return (DoubleMatrix)base.Content; }
|
---|
46 | set { base.Content = value; }
|
---|
47 | }
|
---|
48 |
|
---|
49 | public EnhancedStringConvertibleMatrixView() {
|
---|
50 | InitializeComponent();
|
---|
51 | }
|
---|
52 |
|
---|
53 | public void ResetVisibility() {
|
---|
54 | columnVisibility = null;
|
---|
55 | rowVisibility = null;
|
---|
56 | }
|
---|
57 |
|
---|
58 | protected override void UpdateColumnHeaders() {
|
---|
59 | base.UpdateColumnHeaders();
|
---|
60 | if (columnVisibility != null && Content != null && columnVisibility.Count() == dataGridView.ColumnCount) {
|
---|
61 | int i = 0;
|
---|
62 | foreach (var visibility in columnVisibility) {
|
---|
63 | dataGridView.Columns[i].Visible = visibility;
|
---|
64 | i++;
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
68 | protected override void UpdateRowHeaders() {
|
---|
69 | base.UpdateRowHeaders();
|
---|
70 | if (rowVisibility != null && Content != null && rowVisibility.Count() == dataGridView.RowCount) {
|
---|
71 | int i = 0;
|
---|
72 | foreach (var visibility in rowVisibility) {
|
---|
73 | dataGridView.Rows[i].Visible = visibility;
|
---|
74 | i++;
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | protected virtual void ShowHideRows_Click(object sender, EventArgs e) {
|
---|
80 | var dialog = new StringConvertibleMatrixRowVisibilityDialog(this.dataGridView.Rows.Cast<DataGridViewRow>());
|
---|
81 | dialog.ShowDialog();
|
---|
82 | rowVisibility = dialog.Visibility;
|
---|
83 | }
|
---|
84 |
|
---|
85 | protected override void ShowHideColumns_Click(object sender, EventArgs e) {
|
---|
86 | var dialog = new StringConvertibleMatrixColumnVisibilityDialog(this.dataGridView.Columns.Cast<DataGridViewColumn>());
|
---|
87 | dialog.ShowDialog();
|
---|
88 | columnVisibility = dialog.Visibility;
|
---|
89 | }
|
---|
90 |
|
---|
91 | protected void dataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) {
|
---|
92 | if (Content == null) return;
|
---|
93 | if (e.RowIndex < 0) return;
|
---|
94 | if (e.ColumnIndex < 0) return;
|
---|
95 | if (e.State.HasFlag(DataGridViewElementStates.Selected)) return;
|
---|
96 | if (!e.PaintParts.HasFlag(DataGridViewPaintParts.Background)) return;
|
---|
97 |
|
---|
98 | int rowIndex = virtualRowIndices[e.RowIndex];
|
---|
99 | Color backColor = GetDataPointColor(Content[rowIndex, e.ColumnIndex], Minimum, Maximum);
|
---|
100 | using (Brush backColorBrush = new SolidBrush(backColor)) {
|
---|
101 | e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
|
---|
102 | }
|
---|
103 | e.PaintContent(e.CellBounds);
|
---|
104 | e.Handled = true;
|
---|
105 | }
|
---|
106 |
|
---|
107 | protected virtual Color GetDataPointColor(double value, double min, double max) {
|
---|
108 | if (double.IsNaN(value)) {
|
---|
109 | return Color.DarkGray;
|
---|
110 | }
|
---|
111 | IList<Color> colors = ColorGradient.Colors;
|
---|
112 | int index = (int)((colors.Count - 1) * (value - min) / (max - min));
|
---|
113 | if (index >= colors.Count) index = colors.Count - 1;
|
---|
114 | if (index < 0) index = 0;
|
---|
115 | return colors[index];
|
---|
116 | }
|
---|
117 | }
|
---|
118 | }
|
---|