Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.Analysis/3.3/HeatMap.cs @ 5593

Last change on this file since 5593 was 4739, checked in by swagner, 14 years ago

Worked on population diversity analysis (#1188)

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