Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Analysis.Views/3.3/HeatMapView.cs @ 14226

Last change on this file since 14226 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 5.4 KB
RevLine 
[4703]1#region License Information
2/* HeuristicLab
[14185]3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[4703]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;
[4808]23using System.Collections.Generic;
[4703]24using System.Drawing;
25using System.Windows.Forms;
26using System.Windows.Forms.DataVisualization.Charting;
[4808]27using HeuristicLab.Common;
[4703]28using HeuristicLab.Core.Views;
29using HeuristicLab.MainForm;
30
31namespace HeuristicLab.Analysis.Views {
32  [View("HeatMap View")]
33  [Content(typeof(HeatMap), true)]
34  public partial class HeatMapView : ItemView {
[4739]35    protected static Color[] colors = new Color[256];
[4703]36    public new HeatMap Content {
37      get { return (HeatMap)base.Content; }
38      set { base.Content = value; }
39    }
40
41    public HeatMapView() {
42      InitializeComponent();
43      chart.CustomizeAllChartAreas();
44    }
45
[4739]46    protected override void DeregisterContentEvents() {
47      Content.TitleChanged -= new EventHandler(Content_TitleChanged);
48      Content.MinimumChanged -= new EventHandler(Content_MinimumChanged);
49      Content.MaximumChanged -= new EventHandler(Content_MaximumChanged);
50      base.DeregisterContentEvents();
51    }
52    protected override void RegisterContentEvents() {
53      base.RegisterContentEvents();
54      Content.TitleChanged += new EventHandler(Content_TitleChanged);
55      Content.MinimumChanged += new EventHandler(Content_MinimumChanged);
56      Content.MaximumChanged += new EventHandler(Content_MaximumChanged);
57    }
58
[4703]59    protected override void OnContentChanged() {
60      base.OnContentChanged();
61      if (Content == null) {
62        chart.Series.Clear();
[4739]63        chart.Titles[0].Text = "Heat Map";
64        minimumLabel.Text = "0.0";
65        maximumLabel.Text = "1.0";
[4703]66      } else {
[4739]67        chart.Titles[0].Text = Content.Title;
68        minimumLabel.Text = Content.Minimum.ToString();
69        maximumLabel.Text = Content.Maximum.ToString();
70        UpdatePoints();
[4703]71      }
72    }
73
[4739]74    protected override void SetEnabledStateOfControls() {
75      base.SetEnabledStateOfControls();
76      chart.Enabled = Content != null;
77      grayscaleCheckBox.Enabled = Content != null;
78    }
79
80    protected virtual void UpdatePoints() {
[4703]81      chart.Series.Clear();
82      Series series = new Series();
83      series.ChartType = SeriesChartType.Point;
84      series.XValueType = ChartValueType.Int32;
85      series.YValueType = ChartValueType.Int32;
86      series.YAxisType = AxisType.Primary;
[4739]87      for (int i = 1; i < Content.Rows + 1; i++)
88        for (int j = 1; j < Content.Columns + 1; j++)
89          series.Points.Add(CreateDataPoint(j, i, Content[i - 1, j - 1]));
90      chart.ChartAreas[0].AxisX.Minimum = 0;
91      chart.ChartAreas[0].AxisX.Maximum = Content.Columns + 1;
[4703]92      chart.ChartAreas[0].AxisY.Minimum = 0;
[4739]93      chart.ChartAreas[0].AxisY.Maximum = Content.Rows + 1;
[4703]94      chart.Series.Add(series);
95    }
96
[4739]97    protected virtual DataPoint CreateDataPoint(int index1, int index2, double value) {
[4703]98      DataPoint p = new DataPoint(index1, index2);
[4739]99      p.Color = GetDataPointColor(value, Content.Minimum, Content.Maximum, grayscaleCheckBox.Checked);
[4703]100      p.MarkerStyle = MarkerStyle.Square;
101      return p;
102    }
103
[4739]104    protected virtual Color GetDataPointColor(double value, double min, double max, bool grayscale) {
[4808]105      IList<Color> colors = grayscale ? ColorGradient.GrayscaledColors : ColorGradient.Colors;
106      int index = (int)((colors.Count - 1) * (value - min) / (max - min));
107      if (index >= colors.Count) index = colors.Count - 1;
[4739]108      if (index < 0) index = 0;
[4808]109      return colors[index];
[4739]110    }
[4703]111
[4739]112    #region Content Events
113    protected virtual void Content_TitleChanged(object sender, EventArgs e) {
114      if (InvokeRequired)
115        Invoke(new EventHandler(Content_TitleChanged), sender, e);
116      else {
117        chart.Titles[0].Text = Content.Title;
118      }
[4703]119    }
[4739]120    protected virtual void Content_MinimumChanged(object sender, EventArgs e) {
121      if (InvokeRequired)
122        Invoke(new EventHandler(Content_MinimumChanged), sender, e);
123      else {
124        minimumLabel.Text = Content.Minimum.ToString();
125        UpdatePoints();
126      }
127    }
128    protected virtual void Content_MaximumChanged(object sender, EventArgs e) {
129      if (InvokeRequired)
130        Invoke(new EventHandler(Content_MaximumChanged), sender, e);
131      else {
132        maximumLabel.Text = Content.Maximum.ToString();
133        UpdatePoints();
134      }
135    }
136    #endregion
[4703]137
[4739]138    #region Control Events
139    protected virtual void grayscaledImagesCheckBox_CheckedChanged(object sender, EventArgs e) {
140      grayscalesPictureBox.Visible = grayscaleCheckBox.Checked;
141      colorsPictureBox.Visible = !grayscaleCheckBox.Checked;
142      UpdatePoints();
143    }
[4703]144    #endregion
145  }
146}
Note: See TracBrowser for help on using the repository browser.