Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Charting/BubbleChartControl.cs @ 1528

Last change on this file since 1528 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: 6.4 KB
RevLine 
[561]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;
[566]26using System.Drawing.Drawing2D;
[561]27using System.Data;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.Charting;
31
32namespace HeuristicLab.CEDMA.Charting {
[566]33  public partial class BubbleChartControl : UserControl {
34    private Bitmap bitmap;
35    private bool renderingRequired;
[567]36    private Point mousePosition;
[566]37    private Point buttonDownPoint;
[567]38
[566]39    private BubbleChart myChart;
40    public BubbleChart Chart {
41      get { return myChart; }
[561]42      set {
[566]43        if(myChart != null) myChart.Update -= new EventHandler(myChart_Update);
44        myChart = value;
45        if(myChart != null) {
46          myChart.Update += new EventHandler(myChart_Update);
47          SetMode(Chart.Mode);
[561]48        }
[566]49        GenerateImage();
[561]50      }
51    }
[566]52    private bool myScaleOnResize;
53    public bool ScaleOnResize {
54      get { return myScaleOnResize; }
55      set { myScaleOnResize = value; }
[561]56    }
57
58    public BubbleChartControl() {
59      InitializeComponent();
[566]60      myScaleOnResize = true;
61      GenerateImage();
[561]62    }
[566]63
64    private void myChart_Update(object sender, EventArgs e) {
65      GenerateImage();
66    }
67    private void pictureBox_SizeChanged(object sender, EventArgs e) {
68      if(ScaleOnResize) {
69        if((pictureBox.Width > 0) && (pictureBox.Height > 0) && (Chart != null)) {
70          PointD point = Chart.TransformPixelToWorld(new Point(pictureBox.Width, Chart.SizeInPixels.Height - pictureBox.Height));
71          Chart.SetPosition(Chart.LowerLeft, point);
72        }
73      }
74      GenerateImage();
75    }
76    private void pictureBox_VisibleChanged(object sender, EventArgs e) {
77      if(pictureBox.Visible && renderingRequired) {
78        GenerateImage();
79      }
80    }
81
82    private void pictureBox_MouseDown(object sender, MouseEventArgs e) {
83      buttonDownPoint = e.Location;
84    }
85    private void pictureBox_MouseUp(object sender, MouseEventArgs e) {
86      if(e.Button == MouseButtons.Left) {
87        Point lowerLeft = new Point(Math.Min(e.X, buttonDownPoint.X),
88                                    Math.Max(e.Y, buttonDownPoint.Y));
89        Point upperRight = new Point(Math.Max(e.X, buttonDownPoint.X),
90                                     Math.Min(e.Y, buttonDownPoint.Y));
91        if(Chart.Mode == ChartMode.Zoom) {
92          pictureBox.Refresh();
93          if((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y)) {
94            Chart.ZoomIn(lowerLeft, upperRight);
95          }
96        } else if(Chart.Mode == ChartMode.Select) {
97          if((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y)) {
98            Chart.MouseDrag(lowerLeft, upperRight, e.Button);
99          }
[567]100        } else if(Chart.Mode == ChartMode.Move) {
[566]101        }
102      } else if(e.Button == MouseButtons.Middle) {
103        if(Chart.Mode == ChartMode.Zoom) {
[567]104          Chart.ZoomOut();
[566]105        }
106      }
107    }
108    private void pictureBox_MouseMove(object sender, MouseEventArgs e) {
109      toolTip.SetToolTip(pictureBox, Chart.GetToolTipText(e.Location));
110      if(e.Button != MouseButtons.None) {
111        if((Chart.Mode == ChartMode.Zoom || Chart.Mode == ChartMode.Select) && (e.Button == MouseButtons.Left)) {
112          pictureBox.Refresh();
113          Graphics graphics = pictureBox.CreateGraphics();
114          Pen pen = new Pen(Color.Gray);
115          pen.DashStyle = DashStyle.Dash;
116          graphics.DrawRectangle(pen,
117                                 Math.Min(e.X, buttonDownPoint.X),
118                                 Math.Min(e.Y, buttonDownPoint.Y),
119                                 Math.Abs(e.X - buttonDownPoint.X),
120                                 Math.Abs(e.Y - buttonDownPoint.Y));
121          pen.Dispose();
122          graphics.Dispose();
123        }
124      }
125      mousePosition = e.Location;
126    }
127
128    private void zoomToolStripMenuItem_Click(object sender, EventArgs e) {
129      SetMode(ChartMode.Zoom);
130    }
131    private void selectToolStripMenuItem_Click(object sender, EventArgs e) {
132      SetMode(ChartMode.Select);
133    }
[567]134    private void moveToolStripMenuItem_Click(object sender, EventArgs e) {
135      SetMode(ChartMode.Move);
136    }
[566]137
138    private void GenerateImage() {
139      if(!Visible) {
140        renderingRequired = true;
141      } else {
142        if((pictureBox.Width == 0) || (pictureBox.Height == 0)) {
143          bitmap = null;
144        } else {
145          bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
146          if(Chart != null) {
147            Graphics graphics = Graphics.FromImage(bitmap);
148            graphics.SetClip(new System.Drawing.Rectangle(0, 0, pictureBox.Width, pictureBox.Height));
149            Chart.Render(graphics, pictureBox.Width, pictureBox.Height);
150            graphics.Dispose();
151          }
152        }
153        pictureBox.Image = bitmap;
154        renderingRequired = false;
155      }
156    }
157
158    private void SetMode(ChartMode mode) {
159      zoomToolStripMenuItem.Checked = false;
160      selectToolStripMenuItem.Checked = false;
[567]161      moveToolStripMenuItem.Checked = false;
[566]162      if(mode == ChartMode.Zoom) zoomToolStripMenuItem.Checked = true;
163      else if(mode == ChartMode.Select) selectToolStripMenuItem.Checked = true;
[567]164      else if(mode == ChartMode.Move) moveToolStripMenuItem.Checked = true;
[566]165      Chart.Mode = mode;
166    }
167
168    private void pictureBox_MouseClick(object sender, MouseEventArgs e) {
[569]169      Chart.MouseClick(e.Location, e.Button);
[566]170    }
171
172    private void pictureBox_MouseDoubleClick(object sender, MouseEventArgs e) {
[569]173      Chart.MouseDoubleClick(e.Location, e.Button);
[566]174    }
[561]175  }
176}
Note: See TracBrowser for help on using the repository browser.