Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2291 was 2289, checked in by mkommend, 15 years ago
  • added VisualMatrix to represent data in BubbleChart
  • made BubbleChart abstract and added inherited ModelingBubbleChart, which reacts as the BubbleChart
  • moved classes between CEDMA.Core and CEDMA.Charting
  • deleted unnecessary classes (results, resultsentry)

(ticket #723)

File size: 7.4 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 BubbleChartControl : UserControl {
34    private Bitmap bitmap;
35    private bool renderingRequired;
36    private Point mousePosition;
37    private Point buttonDownPoint;
38    private IPrimitive primitiveUnderCursor;
39
40    private BubbleChart myChart;
41    public BubbleChart Chart {
42      get { return myChart; }
43      set {
44        if(myChart != null) myChart.Update -= new EventHandler(myChart_Update);
45        myChart = value;
46        if(myChart != null) {
47          myChart.Update += new EventHandler(myChart_Update);
48          SetMode(Chart.Mode);
49        }
50        GenerateImage();
51      }
52    }
53    private bool myScaleOnResize;
54    public bool ScaleOnResize {
55      get { return myScaleOnResize; }
56      set { myScaleOnResize = value; }
57    }
58
59    public BubbleChartControl() {
60      InitializeComponent();
61      myScaleOnResize = true;
62      GenerateImage();
63    }
64
65    private void myChart_Update(object sender, EventArgs e) {
66      GenerateImage();
67    }
68    private void pictureBox_SizeChanged(object sender, EventArgs e) {
69      if(ScaleOnResize) {
70        if((pictureBox.Width > 0) && (pictureBox.Height > 0) && (Chart != null)) {
71          PointD point = Chart.TransformPixelToWorld(new Point(pictureBox.Width, Chart.SizeInPixels.Height - pictureBox.Height));
72          Chart.SetPosition(Chart.LowerLeft, point);
73        }
74      }
75      GenerateImage();
76    }
77    private void pictureBox_VisibleChanged(object sender, EventArgs e) {
78      if(pictureBox.Visible && renderingRequired) {
79        GenerateImage();
80      }
81    }
82
83    private void pictureBox_MouseDown(object sender, MouseEventArgs e) {
84      buttonDownPoint = e.Location;
85    }
86    private void pictureBox_MouseUp(object sender, MouseEventArgs e) {
87      if(e.Button == MouseButtons.Left) {
88        Point lowerLeft = new Point(Math.Min(e.X, buttonDownPoint.X),
89                                    Math.Max(e.Y, buttonDownPoint.Y));
90        Point upperRight = new Point(Math.Max(e.X, buttonDownPoint.X),
91                                     Math.Min(e.Y, buttonDownPoint.Y));
92        if(Chart.Mode == ChartMode.Zoom) {
93          pictureBox.Refresh();
94          if((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y)) {
95            Chart.ZoomIn(lowerLeft, upperRight);
96          }
97        } else if(Chart.Mode == ChartMode.Select) {
98          if((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y)) {
99            Chart.MouseDrag(lowerLeft, upperRight, e.Button);
100          }
101        } else if(Chart.Mode == ChartMode.Move) {
102        }
103      } else if(e.Button == MouseButtons.Middle) {
104        if(Chart.Mode == ChartMode.Zoom) {
105          Chart.ZoomOut();
106        }
107      }
108    }
109    private void pictureBox_MouseMove(object sender, MouseEventArgs e) {
110      if (Chart.GetPrimitive(e.Location) != primitiveUnderCursor) {
111        primitiveUnderCursor = Chart.GetPrimitive(e.Location);
112        toolTip.SetToolTip(pictureBox, Chart.GetToolTipText(e.Location));
113      }
114      if(e.Button != MouseButtons.None) {
115        if((Chart.Mode == ChartMode.Zoom || Chart.Mode == ChartMode.Select) && (e.Button == MouseButtons.Left)) {
116          pictureBox.Refresh();
117          Graphics graphics = pictureBox.CreateGraphics();
118          Pen pen = new Pen(Color.Gray);
119          pen.DashStyle = DashStyle.Dash;
120          graphics.DrawRectangle(pen,
121                                 Math.Min(e.X, buttonDownPoint.X),
122                                 Math.Min(e.Y, buttonDownPoint.Y),
123                                 Math.Abs(e.X - buttonDownPoint.X),
124                                 Math.Abs(e.Y - buttonDownPoint.Y));
125          pen.Dispose();
126          graphics.Dispose();
127        }
128      }
129      mousePosition = e.Location;
130    }
131
132    private void zoomToolStripMenuItem_Click(object sender, EventArgs e) {
133      SetMode(ChartMode.Zoom);
134    }
135    private void selectToolStripMenuItem_Click(object sender, EventArgs e) {
136      SetMode(ChartMode.Select);
137    }
138    private void moveToolStripMenuItem_Click(object sender, EventArgs e) {
139      SetMode(ChartMode.Move);
140    }
141
142    private void GenerateImage() {
143      if(!Visible) {
144        renderingRequired = true;
145      } else {
146        if((pictureBox.Width == 0) || (pictureBox.Height == 0)) {
147          bitmap = null;
148        } else {
149          bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
150          if(Chart != null) {
151            Graphics graphics = Graphics.FromImage(bitmap);
152            graphics.SetClip(new System.Drawing.Rectangle(0, 0, pictureBox.Width, pictureBox.Height));
153            Chart.Render(graphics, pictureBox.Width, pictureBox.Height);
154            graphics.Dispose();
155          }
156        }
157        pictureBox.Image = bitmap;
158        renderingRequired = false;
159      }
160    }
161
162    private void SetMode(ChartMode mode) {
163      zoomToolStripMenuItem.Checked = false;
164      selectToolStripMenuItem.Checked = false;
165      moveToolStripMenuItem.Checked = false;
166      if(mode == ChartMode.Zoom) zoomToolStripMenuItem.Checked = true;
167      else if(mode == ChartMode.Select) selectToolStripMenuItem.Checked = true;
168      else if(mode == ChartMode.Move) moveToolStripMenuItem.Checked = true;
169      Chart.Mode = mode;
170    }
171
172    private void pictureBox_MouseClick(object sender, MouseEventArgs e) {
173      Chart.MouseClick(e.Location, e.Button);
174    }
175
176    private void pictureBox_MouseDoubleClick(object sender, MouseEventArgs e) {
177      Chart.MouseDoubleClick(e.Location, e.Button);
178    }
179
180    private void invertSelectionToolStripMenuItem_Click(object sender, EventArgs e) {
181      Chart.ToggleSelected();
182    }
183
184    private void hideSelectedToolStripMenuItem_Click(object sender, EventArgs e) {
185      showHiddenToolStripMenuItem.Enabled = true;
186      Chart.ApplyFilter(x => x.Selected == true && x.Visible==true);
187    }
188
189    private void clearSelectionMenuItem_Click(object sender, EventArgs e) {
190      Chart.ClearSelection();
191    }
192
193    private void showHiddenToolStripMenuItem_Click(object sender, EventArgs e) {
194      Chart.ClearFilter();
195      showHiddenToolStripMenuItem.Enabled = false;
196    }
197
198    private void pictureBoxContextMenuStrip_Opening(object sender, CancelEventArgs e) {
199
200    }
201
202    private void toolTip_Popup(object sender, PopupEventArgs e) {
203
204    }
205  }
206}
Note: See TracBrowser for help on using the repository browser.