Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Charting/HistogramControl.cs @ 593

Last change on this file since 593 was 571, checked in by gkronber, 16 years ago

implemented basic histogram (without 'brushing'). #271 (Functionality to show frequency distribution of any variable (histograms))

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.ComponentModel;
25using System.Drawing;
26using System.Drawing.Drawing2D;
27using System.Data;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.Charting;
31
32namespace HeuristicLab.CEDMA.Charting {
33  public partial class HistogramControl : UserControl {
34    private Bitmap bitmap;
35    private bool renderingRequired;
36
37    private Histogram myChart;
38    public Histogram Chart {
39      get { return myChart; }
40      set {
41        if(myChart != null) myChart.Update -= new EventHandler(myChart_Update);
42        myChart = value;
43        if(myChart != null) {
44          myChart.Update += new EventHandler(myChart_Update);
45        }
46        GenerateImage();
47      }
48    }
49
50    public HistogramControl() {
51      InitializeComponent();
52      GenerateImage();
53    }
54
55    private void myChart_Update(object sender, EventArgs e) {
56      GenerateImage();
57    }
58
59    private void pictureBox_SizeChanged(object sender, EventArgs e) {
60      GenerateImage();
61    }
62    private void pictureBox_VisibleChanged(object sender, EventArgs e) {
63      if(pictureBox.Visible && renderingRequired) {
64        GenerateImage();
65      }
66    }
67
68    private void pictureBox_MouseMove(object sender, MouseEventArgs e) {
69      toolTip.SetToolTip(pictureBox, Chart.GetToolTipText(e.Location));
70    }
71
72    private void GenerateImage() {
73      if(!Visible) {
74        renderingRequired = true;
75      } else {
76        if((pictureBox.Width == 0) || (pictureBox.Height == 0)) {
77          bitmap = null;
78        } else {
79          bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
80          if(Chart != null) {
81            Graphics graphics = Graphics.FromImage(bitmap);
82            graphics.SetClip(new System.Drawing.Rectangle(0, 0, pictureBox.Width, pictureBox.Height));
83            Chart.Render(graphics, pictureBox.Width, pictureBox.Height);
84            graphics.Dispose();
85          }
86        }
87        pictureBox.Image = bitmap;
88        renderingRequired = false;
89      }
90    }
91
92    private void pictureBox_MouseClick(object sender, MouseEventArgs e) {
93      Chart.MouseClick(e.Location, e.Button);
94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.