Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/14/08 10:13:32 (16 years ago)
Author:
gkronber
Message:

implemented 'brushing' and cleaned up code a little bit. #270 (Selection of multiple points)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Charting/BubbleChartControl.cs

    r561 r566  
    2424using System.ComponentModel;
    2525using System.Drawing;
     26using System.Drawing.Drawing2D;
    2627using System.Data;
    2728using System.Text;
     
    3031
    3132namespace HeuristicLab.CEDMA.Charting {
    32   public partial class BubbleChartControl : ChartControl {
    33     public new BubbleChart Chart {
    34       get { return (BubbleChart)base.Chart; }
     33  public partial class BubbleChartControl : UserControl {
     34    private Bitmap bitmap;
     35    private bool renderingRequired;
     36    private Point buttonDownPoint;
     37    private Point mousePosition;
     38    private int mouseClickCount;
     39    private DateTime lastRendered = DateTime.Now;
     40    private BubbleChart myChart;
     41    public BubbleChart Chart {
     42      get { return myChart; }
    3543      set {
    36         if (Chart != null) {
    37           Chart.Update -= new EventHandler(Chart_Update);
     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);
    3849        }
    39         base.Chart = value;
    40         if (Chart != null) {
    41           Chart.Update += new EventHandler(Chart_Update);
    42         }
     50        GenerateImage();
    4351      }
    4452    }
    45 
    46     void Chart_Update(object sender, EventArgs e) {
    47       // do nothing;
     53    private bool myScaleOnResize;
     54    public bool ScaleOnResize {
     55      get { return myScaleOnResize; }
     56      set { myScaleOnResize = value; }
    4857    }
    4958
    5059    public BubbleChartControl() {
    5160      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      mouseClickCount = e.Clicks;
     86    }
     87    private void pictureBox_MouseUp(object sender, MouseEventArgs e) {
     88      if(e.Button == MouseButtons.Left) {
     89        Point lowerLeft = new Point(Math.Min(e.X, buttonDownPoint.X),
     90                                    Math.Max(e.Y, buttonDownPoint.Y));
     91        Point upperRight = new Point(Math.Max(e.X, buttonDownPoint.X),
     92                                     Math.Min(e.Y, buttonDownPoint.Y));
     93        if(Chart.Mode == ChartMode.Zoom) {
     94          pictureBox.Refresh();
     95          if((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y)) {
     96            Chart.ZoomIn(lowerLeft, upperRight);
     97          }
     98        } else if(Chart.Mode == ChartMode.Select) {
     99          if((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y)) {
     100            Chart.MouseDrag(lowerLeft, upperRight, e.Button);
     101          }
     102        }
     103      } else if(e.Button == MouseButtons.Middle) {
     104        if(Chart.Mode == ChartMode.Zoom) {
     105          if(mouseClickCount == 1) Chart.ZoomOut();
     106          else if(mouseClickCount == 2) Chart.Unzoom();
     107        }
     108      }
     109    }
     110    private void pictureBox_MouseMove(object sender, MouseEventArgs e) {
     111      toolTip.SetToolTip(pictureBox, Chart.GetToolTipText(e.Location));
     112      Cursor cursor = Chart.GetCursor(e.Location);
     113      if(cursor != null) pictureBox.Cursor = cursor;
     114      else pictureBox.Cursor = Cursors.Default;
     115
     116      if(e.Button != MouseButtons.None) {
     117        if((Chart.Mode == ChartMode.Zoom || Chart.Mode == ChartMode.Select) && (e.Button == MouseButtons.Left)) {
     118          pictureBox.Refresh();
     119          Graphics graphics = pictureBox.CreateGraphics();
     120          Pen pen = new Pen(Color.Gray);
     121          pen.DashStyle = DashStyle.Dash;
     122          graphics.DrawRectangle(pen,
     123                                 Math.Min(e.X, buttonDownPoint.X),
     124                                 Math.Min(e.Y, buttonDownPoint.Y),
     125                                 Math.Abs(e.X - buttonDownPoint.X),
     126                                 Math.Abs(e.Y - buttonDownPoint.Y));
     127          pen.Dispose();
     128          graphics.Dispose();
     129        }
     130      }
     131      mousePosition = e.Location;
     132    }
     133
     134    private void zoomToolStripMenuItem_Click(object sender, EventArgs e) {
     135      SetMode(ChartMode.Zoom);
     136    }
     137    private void selectToolStripMenuItem_Click(object sender, EventArgs e) {
     138      SetMode(ChartMode.Select);
     139    }
     140
     141    private void GenerateImage() {
     142      if(!Visible) {
     143        renderingRequired = true;
     144      } else {
     145        if((pictureBox.Width == 0) || (pictureBox.Height == 0)) {
     146          bitmap = null;
     147        } else {
     148          bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
     149          if(Chart != null) {
     150            Graphics graphics = Graphics.FromImage(bitmap);
     151            graphics.SetClip(new System.Drawing.Rectangle(0, 0, pictureBox.Width, pictureBox.Height));
     152            Chart.Render(graphics, pictureBox.Width, pictureBox.Height);
     153            graphics.Dispose();
     154          }
     155        }
     156        pictureBox.Image = bitmap;
     157        renderingRequired = false;
     158      }
     159    }
     160
     161    private void SetMode(ChartMode mode) {
     162      zoomToolStripMenuItem.Checked = false;
     163      selectToolStripMenuItem.Checked = false;
     164      if(mode == ChartMode.Zoom) zoomToolStripMenuItem.Checked = true;
     165      else if(mode == ChartMode.Select) selectToolStripMenuItem.Checked = true;
     166      Chart.Mode = mode;
     167    }
     168
     169    private void pictureBox_MouseClick(object sender, MouseEventArgs e) {
     170      Chart.MouseClick(e.Location, e.Button);
     171    }
     172
     173    private void pictureBox_MouseDoubleClick(object sender, MouseEventArgs e) {
     174      Chart.MouseDoubleClick(e.Location, e.Button);
    52175    }
    53176  }
Note: See TracChangeset for help on using the changeset viewer.