1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2014 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.Drawing;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Analysis {
|
---|
30 | [Item("HeatMap", "Represents a heat map of double values.")]
|
---|
31 | [StorableClass]
|
---|
32 | public class HeatMap : DoubleMatrix {
|
---|
33 | public static new Image StaticItemImage {
|
---|
34 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Gradient; }
|
---|
35 | }
|
---|
36 |
|
---|
37 | private string title;
|
---|
38 | public string Title {
|
---|
39 | get { return title; }
|
---|
40 | set {
|
---|
41 | if (value == null) value = string.Empty;
|
---|
42 | if (title != value) {
|
---|
43 | title = value;
|
---|
44 | OnTitleChanged();
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
48 | private double minimum;
|
---|
49 | public double Minimum {
|
---|
50 | get { return minimum; }
|
---|
51 | set {
|
---|
52 | if (minimum != value) {
|
---|
53 | minimum = value;
|
---|
54 | if (minimum >= maximum) Maximum = minimum + 1.0;
|
---|
55 | OnMinimumChanged();
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 | private double maximum;
|
---|
60 | public double Maximum {
|
---|
61 | get { return maximum; }
|
---|
62 | set {
|
---|
63 | if (maximum != value) {
|
---|
64 | maximum = value;
|
---|
65 | if (maximum <= minimum) Minimum = maximum - 1.0;
|
---|
66 | OnMaximumChanged();
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | #region Storable Properties
|
---|
72 | [Storable(Name = "Title")]
|
---|
73 | private string StorableTitle {
|
---|
74 | get { return title; }
|
---|
75 | set { title = value; }
|
---|
76 | }
|
---|
77 | [Storable(Name = "Minimum")]
|
---|
78 | private double StorableMinimum {
|
---|
79 | get { return minimum; }
|
---|
80 | set { minimum = value; }
|
---|
81 | }
|
---|
82 | [Storable(Name = "Maximum")]
|
---|
83 | private double StorableMaximum {
|
---|
84 | get { return maximum; }
|
---|
85 | set { maximum = value; }
|
---|
86 | }
|
---|
87 | #endregion
|
---|
88 |
|
---|
89 | [StorableConstructor]
|
---|
90 | protected HeatMap(bool deserializing) : base(deserializing) { }
|
---|
91 | protected HeatMap(HeatMap original, Cloner cloner)
|
---|
92 | : base(original, cloner) {
|
---|
93 | this.title = original.title;
|
---|
94 | this.minimum = original.minimum;
|
---|
95 | this.maximum = original.maximum;
|
---|
96 | }
|
---|
97 | public HeatMap()
|
---|
98 | : base() {
|
---|
99 | this.title = "Heat Map";
|
---|
100 | this.minimum = 0.0;
|
---|
101 | this.maximum = 1.0;
|
---|
102 | }
|
---|
103 | public HeatMap(int rows, int columns)
|
---|
104 | : base(rows, columns) {
|
---|
105 | this.title = "Heat Map";
|
---|
106 | this.minimum = 0.0;
|
---|
107 | this.maximum = 1.0;
|
---|
108 | }
|
---|
109 | public HeatMap(int rows, int columns, string title)
|
---|
110 | : base(rows, columns) {
|
---|
111 | this.title = title == null ? string.Empty : title;
|
---|
112 | this.minimum = 0.0;
|
---|
113 | this.maximum = 1.0;
|
---|
114 | }
|
---|
115 | public HeatMap(double[,] elements)
|
---|
116 | : base(elements) {
|
---|
117 | this.title = "Heat Map";
|
---|
118 | this.minimum = 0.0;
|
---|
119 | this.maximum = 1.0;
|
---|
120 | }
|
---|
121 | public HeatMap(double[,] elements, string title)
|
---|
122 | : base(elements) {
|
---|
123 | this.title = title == null ? string.Empty : title;
|
---|
124 | this.minimum = 0.0;
|
---|
125 | this.maximum = 1.0;
|
---|
126 | }
|
---|
127 | public HeatMap(double[,] elements, string title, double minimum, double maximum)
|
---|
128 | : base(elements) {
|
---|
129 | this.title = title == null ? string.Empty : title;
|
---|
130 | if (minimum >= maximum) throw new ArgumentException("Minimum is larger than or equal to maximum");
|
---|
131 | this.minimum = minimum;
|
---|
132 | this.maximum = maximum;
|
---|
133 | }
|
---|
134 |
|
---|
135 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
136 | return new HeatMap(this, cloner);
|
---|
137 | }
|
---|
138 |
|
---|
139 | public override string ToString() {
|
---|
140 | return Title;
|
---|
141 | }
|
---|
142 |
|
---|
143 | public event EventHandler TitleChanged;
|
---|
144 | protected virtual void OnTitleChanged() {
|
---|
145 | var handler = TitleChanged;
|
---|
146 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
147 | }
|
---|
148 | public event EventHandler MinimumChanged;
|
---|
149 | protected virtual void OnMinimumChanged() {
|
---|
150 | var handler = MinimumChanged;
|
---|
151 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
152 | }
|
---|
153 | public event EventHandler MaximumChanged;
|
---|
154 | protected virtual void OnMaximumChanged() {
|
---|
155 | var handler = MaximumChanged;
|
---|
156 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
157 | }
|
---|
158 | }
|
---|
159 | }
|
---|