Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13114


Ignore:
Timestamp:
11/04/15 13:50:43 (9 years ago)
Author:
jkarder
Message:

#1265: worked on visualization

  • removed BackgroundColor and PictureBox from ChartControl
  • updated chart modes
Location:
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartControl.cs

    r13106 r13114  
    3737    private bool SuppressRender { get; set; }
    3838
    39     public PictureBox PictureBox { get { return pictureBox; } }
    40 
    41     public Color BackgroundColor {
    42       get { return chart != null ? chart.BackgroundColor : Color.Empty; }
    43       set {
    44         if (chart == null || chart.BackgroundColor == value) return;
    45         chart.BackgroundColor = value;
    46       }
    47     }
    48 
    4939    private IChart chart;
    5040    public IChart Chart {
     
    112102      SuppressRender = false;
    113103      if (Chart != null) GenerateImage();
     104    }
     105
     106    public void RefreshPicture() {
     107      pictureBox.Refresh();
     108    }
     109
     110    public void UpdatePicture() {
     111      pictureBox.Update();
     112    }
     113
     114    public Graphics CreatePictureGraphics() {
     115      return pictureBox.CreateGraphics();
    114116    }
    115117
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/PanChartMode.cs

    r13108 r13114  
    3535    public PanChartMode(ChartControl control) : base(control) { }
    3636
    37     public override void HandleOnMouseUp(object sender, MouseEventArgs e) {
    38       base.HandleOnMouseUp(sender, e);
    39 
    40       switch (e.Button) {
    41         case MouseButtons.Middle:
    42           chartControl.Chart.Unzoom();
    43           break;
    44       }
    45     }
    46 
    4737    public override void HandleOnMouseMove(object sender, MouseEventArgs e) {
    4838      try {
     
    5646        }
    5747      } finally {
    58         chartControl.PictureBox.Update();
     48        chartControl.UpdatePicture();
    5949        base.HandleOnMouseMove(sender, e);
    6050      }
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/RulerChartMode.cs

    r13108 r13114  
    4343    public RulerChartMode(ChartControl control) : base(control) { }
    4444
     45    public override void HandleOnMouseDown(object sender, MouseEventArgs e) {
     46      try {
     47        if (startPoint.HasValue) {
     48          if (startPoint.Value == e.Location) {
     49            startPoint = null;
     50            chartControl.RefreshPicture();
     51          }
     52        } else
     53          startPoint = e.Location;
     54      } finally {
     55        base.HandleOnMouseDown(sender, e);
     56      }
     57    }
     58
    4559    public override void HandleOnMouseMove(object sender, MouseEventArgs e) {
    46       if (startPoint.HasValue) {
    47         try {
    48           chartControl.PictureBox.Refresh();
    49           DrawCross(startPoint.Value);
    50           DrawCross(e.Location);
    51           DrawLineBetweenLocations(startPoint.Value, e.Location);
    52         } finally {
    53           chartControl.PictureBox.Update();
    54           base.HandleOnMouseMove(sender, e);
     60      try {
     61        if (startPoint.HasValue) {
     62          chartControl.RefreshPicture();
     63          using (var graphics = chartControl.CreatePictureGraphics()) {
     64            DrawCross(graphics, startPoint.Value);
     65            DrawCross(graphics, e.Location);
     66            DrawLineBetweenLocations(graphics, startPoint.Value, e.Location);
     67          }
    5568        }
     69      } finally {
     70        base.HandleOnMouseMove(sender, e);
    5671      }
    5772    }
    5873
    5974    public override void HandleOnMouseUp(object sender, MouseEventArgs e) {
    60       base.HandleOnMouseUp(sender, e);
    61 
    62       switch (e.Button) {
    63         case MouseButtons.Left:
    64           if (!startPoint.HasValue)
    65             startPoint = e.Location;
    66           else {
    67             if (e.Location != startPoint.Value)
    68               DrawInfoBox(e.Location);
    69             else {
    70               chartControl.PictureBox.Refresh();
    71               chartControl.PictureBox.Update();
     75      try {
     76        switch (e.Button) {
     77          case MouseButtons.Left:
     78            if (startPoint.HasValue && startPoint.Value != e.Location) {
     79              using (var graphics = chartControl.CreatePictureGraphics())
     80                DrawInfoBox(graphics, e.Location);
     81              startPoint = null;
    7282            }
    73 
    74             startPoint = null;
    75           }
    76           break;
     83            break;
     84        }
     85      } finally {
     86        base.HandleOnMouseUp(sender, e);
    7787      }
    7888    }
    7989
    80     protected virtual void DrawCross(Point point) {
    81       using (var graphics = chartControl.PictureBox.CreateGraphics())
     90    protected virtual void DrawCross(Graphics graphics, Point point) {
    8291      using (var pen = new Pen(Color.Red)) {
    8392        graphics.DrawLine(pen, point.X - 3, point.Y - 3, point.X + 3, point.Y + 3);
     
    8695    }
    8796
    88     protected virtual void DrawLineBetweenLocations(Point startLocation, Point endLocation) {
    89       using (var graphics = chartControl.PictureBox.CreateGraphics())
     97    protected virtual void DrawLineBetweenLocations(Graphics graphics, Point startLocation, Point endLocation) {
    9098      using (var pen = new Pen(Color.Red))
    9199        graphics.DrawLine(pen, startLocation.X, startLocation.Y, endLocation.X, endLocation.Y);
    92100    }
    93101
    94     protected virtual void DrawInfoBox(Point location) {
     102    protected virtual void DrawInfoBox(Graphics graphics, Point location) {
    95103      var offsetP = new Size(location.X - startPoint.Value.X, location.Y - startPoint.Value.Y);
    96104      var offsetW = chartControl.Chart.TransformPixelToWorld(offsetP);
     
    98106      double lengthP = Math.Sqrt(Math.Pow(offsetP.Width, 2) + Math.Pow(offsetP.Height, 2));
    99107      double lengthW = Math.Sqrt(Math.Pow(offsetW.Width, 2) + Math.Pow(offsetW.Height, 2));
    100       string text = string.Format("Pixel: {0}{1}World: {2:##.###}", Math.Round(lengthP), Environment.NewLine, Math.Round(lengthW, 3));
     108      string text = string.Format("Pixel: {0} " + Environment.NewLine + "World: {1:##.###}", Math.Round(lengthP), Math.Round(lengthW, 3));
    101109
    102       using (var graphics = chartControl.PictureBox.CreateGraphics()) {
    103         var textSize = graphics.MeasureString(text, SystemFonts.DefaultFont);
    104         int width = (int)Math.Ceiling(textSize.Width);
    105         int height = (int)Math.Ceiling(textSize.Height);
     110      var textSize = graphics.MeasureString(text, SystemFonts.DefaultFont);
     111      int width = (int)Math.Ceiling(textSize.Width);
     112      int height = (int)Math.Ceiling(textSize.Height);
    106113
    107         graphics.FillRectangle(Brushes.White, location.X, location.Y, width, height);
    108         graphics.DrawRectangle(Pens.Red, location.X, location.Y, width, height);
    109         graphics.DrawString(text, SystemFonts.DefaultFont, Brushes.Black, location.X, location.Y + 2);
    110       }
     114      graphics.FillRectangle(Brushes.White, location.X, location.Y, width, height);
     115      graphics.DrawRectangle(Pens.Red, location.X, location.Y, width, height);
     116      graphics.DrawString(text, SystemFonts.DefaultFont, Brushes.Black, location.X, location.Y + 2);
     117
    111118    }
    112119  }
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/SelectChartMode.cs

    r13108 r13114  
    3333
    3434    public override void HandleOnKeyDown(object sender, KeyEventArgs e) {
    35       base.HandleOnKeyDown(sender, e);
    36 
    37       switch (e.KeyCode) {
    38         case Keys.Delete:
    39           if (e.KeyCode == Keys.Delete) {
    40             try {
    41               chartControl.SuspendRendering();
    42               foreach (var primitive in chartControl.Chart.Group.SelectedPrimitives)
    43                 chartControl.Chart.Group.Remove(primitive);
    44             } finally { chartControl.ResumeRendering(); }
    45           }
    46           break;
     35      try {
     36        switch (e.KeyCode) {
     37          case Keys.Delete:
     38            if (e.KeyCode == Keys.Delete) {
     39              try {
     40                chartControl.SuspendRendering();
     41                foreach (var primitive in chartControl.Chart.Group.SelectedPrimitives)
     42                  chartControl.Chart.Group.Remove(primitive);
     43              } finally { chartControl.ResumeRendering(); }
     44            }
     45            break;
     46        }
     47      } finally {
     48        base.HandleOnKeyDown(sender, e);
    4749      }
    4850    }
    4951
    5052    public override void HandleOnMouseDown(object sender, MouseEventArgs e) {
    51       base.HandleOnMouseDown(sender, e);
    52 
    5353      try {
    54         chartControl.SuspendRendering();
    55         var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
    56         foreach (var sp in chartControl.Chart.Group.SelectedPrimitives.Where(x => !x.ContainsPoint(worldLocation)))
    57           sp.Selected = false;
    58         var p = chartControl.Chart.GetPrimitive(e.Location);
    59         if (p != null) p.Selected = true;
    60       } finally { chartControl.ResumeRendering(); }
    61     }
    62 
    63     public override void HandleOnMouseUp(object sender, MouseEventArgs e) {
    64       base.HandleOnMouseUp(sender, e);
    65 
    66       switch (e.Button) {
    67         case MouseButtons.Middle:
    68           try {
    69             chartControl.SuspendRendering();
    70             foreach (var p in chartControl.Chart.Group.SelectedPrimitives)
    71               p.Selected = false;
    72           } finally { chartControl.ResumeRendering(); }
    73           break;
     54        switch (e.Button) {
     55          case MouseButtons.Left:
     56            try {
     57              chartControl.SuspendRendering();
     58              var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
     59              foreach (var sp in chartControl.Chart.Group.SelectedPrimitives.Where(x => !x.ContainsPoint(worldLocation)))
     60                sp.Selected = false;
     61              var p = chartControl.Chart.GetPrimitive(e.Location);
     62              if (p != null) p.Selected = true;
     63            } finally { chartControl.ResumeRendering(); }
     64            break;
     65        }
     66      } finally {
     67        base.HandleOnMouseDown(sender, e);
    7468      }
    7569    }
     
    9286        }
    9387      } finally {
    94         chartControl.PictureBox.Update();
     88        chartControl.UpdatePicture();
    9589        base.HandleOnMouseMove(sender, e);
    9690      }
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/ZoomInChartMode.cs

    r13108 r13114  
    3838
    3939    public override void HandleOnMouseUp(object sender, MouseEventArgs e) {
    40       base.HandleOnMouseUp(sender, e);
    41 
    42       switch (e.Button) {
    43         case MouseButtons.Left:
    44           var lowerLeft = new Point(Math.Min(e.X, buttonDownPoint.X), Math.Max(e.Y, buttonDownPoint.Y));
    45           var upperRight = new Point(Math.Max(e.X, buttonDownPoint.X), Math.Min(e.Y, buttonDownPoint.Y));
    46           if ((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y))
    47             chartControl.Chart.ZoomIn(lowerLeft, upperRight);
    48           else chartControl.Chart.ZoomIn(buttonDownPoint);
    49           break;
    50         case MouseButtons.Middle:
    51           chartControl.Chart.Unzoom();
    52           break;
     40      try {
     41        switch (e.Button) {
     42          case MouseButtons.Left:
     43            var lowerLeft = new Point(Math.Min(e.X, buttonDownPoint.X), Math.Max(e.Y, buttonDownPoint.Y));
     44            var upperRight = new Point(Math.Max(e.X, buttonDownPoint.X), Math.Min(e.Y, buttonDownPoint.Y));
     45            if ((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y))
     46              chartControl.Chart.ZoomIn(lowerLeft, upperRight);
     47            else chartControl.Chart.ZoomIn(buttonDownPoint);
     48            break;
     49          case MouseButtons.Middle:
     50            chartControl.Chart.Unzoom();
     51            break;
     52        }
     53      } finally {
     54        base.HandleOnMouseUp(sender, e);
    5355      }
    5456    }
     
    5860        switch (e.Button) {
    5961          case MouseButtons.Left:
    60             chartControl.PictureBox.Refresh();
    61             using (var graphics = chartControl.PictureBox.CreateGraphics())
     62            chartControl.RefreshPicture();
     63            using (var graphics = chartControl.CreatePictureGraphics())
    6264            using (var pen = new Pen(Color.Gray) { DashStyle = DashStyle.Dash }) {
    6365              graphics.DrawRectangle(pen,
     
    7072        }
    7173      } finally {
    72         chartControl.PictureBox.Update();
     74        chartControl.UpdatePicture();
    7375        base.HandleOnMouseMove(sender, e);
    7476      }
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/ZoomOutChartMode.cs

    r13107 r13114  
    3636
    3737    public override void HandleOnMouseUp(object sender, MouseEventArgs e) {
    38       base.HandleOnMouseUp(sender, e);
    39 
    40       switch (e.Button) {
    41         case MouseButtons.Left:
    42           chartControl.Chart.ZoomOut();
    43           break;
    44         case MouseButtons.Middle:
    45           chartControl.Chart.Unzoom();
    46           break;
     38      try {
     39        switch (e.Button) {
     40          case MouseButtons.Left:
     41            chartControl.Chart.ZoomOut();
     42            break;
     43          case MouseButtons.Middle:
     44            chartControl.Chart.Unzoom();
     45            break;
     46        }
     47      } finally {
     48        base.HandleOnMouseUp(sender, e);
    4749      }
    4850    }
Note: See TracChangeset for help on using the changeset viewer.