Changeset 1249 for trunk/sources
- Timestamp:
- 03/04/09 21:35:43 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization.Test/LegendForm.Designer.cs
r872 r1249 30 30 // 31 31 this.canvasUI.Location = new System.Drawing.Point(12, 12); 32 this.canvasUI.MouseEventListener = null;33 32 this.canvasUI.Name = "canvasUI"; 34 33 this.canvasUI.Size = new System.Drawing.Size(260, 240); -
trunk/sources/HeuristicLab.Visualization.Test/LineChartTestForm.cs
r1038 r1249 25 25 if (view != null) { 26 26 LineChart lineChart = (LineChart)view; 27 lineChart. ResetView();27 lineChart.ZoomToFullView(); 28 28 } 29 29 } -
trunk/sources/HeuristicLab.Visualization.Test/MainForm.Designer.cs
r1045 r1249 32 32 // 33 33 this.canvasUI.Location = new System.Drawing.Point(12, 29); 34 this.canvasUI.MouseEventListener = null;35 34 this.canvasUI.Name = "canvasUI"; 36 35 this.canvasUI.Size = new System.Drawing.Size(800, 571); -
trunk/sources/HeuristicLab.Visualization/CanvasUI.Designer.cs
r724 r1249 33 33 // CanvasUI 34 34 // 35 this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.CanvasUI_MouseMove);36 this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.CanvasUI_MouseUp);37 35 this.ResumeLayout(false); 38 36 -
trunk/sources/HeuristicLab.Visualization/CanvasUI.cs
r1240 r1249 7 7 public partial class CanvasUI : Control { 8 8 private readonly Canvas canvas = new Canvas(); 9 private IMouseEventListener mouseEventListener;10 9 11 10 public CanvasUI() { … … 17 16 public Canvas Canvas { 18 17 get { return canvas; } 19 }20 21 public IMouseEventListener MouseEventListener {22 get { return mouseEventListener; }23 set { mouseEventListener = value; }24 18 } 25 19 … … 44 38 base.OnResize(e); 45 39 } 46 47 private void CanvasUI_MouseMove(object sender, MouseEventArgs e) {48 if (mouseEventListener != null) {49 mouseEventListener.MouseMove(sender, e);50 }51 }52 53 private void CanvasUI_MouseUp(object sender, MouseEventArgs e) {54 if (mouseEventListener != null) {55 mouseEventListener.MouseUp(sender, e);56 }57 }58 40 } 59 41 } -
trunk/sources/HeuristicLab.Visualization/HeuristicLab.Visualization.csproj
r1240 r1249 120 120 <Compile Include="SizeD.cs" /> 121 121 <Compile Include="Transform.cs" /> 122 <Compile Include="Translate.cs" /> 122 123 <Compile Include="WorldShape.cs" /> 123 124 <Compile Include="XAxis.cs" /> -
trunk/sources/HeuristicLab.Visualization/IMouseEventListener.cs
r1055 r1249 6 6 void MouseMove(object sender, MouseEventArgs e); 7 7 void MouseUp(object sender, MouseEventArgs e); 8 9 event MouseEventHandler OnMouseMove;10 event MouseEventHandler OnMouseUp;11 8 } 12 9 13 public delegate void SetNewClippingAreaHandler(RectangleD newClippingArea);14 public delegate void DrawRectangleHandler(Rectangle rectangle);10 public delegate void MoveHandler(Point startPoint, Point endPoint); 11 public delegate void RectangleHandler(Rectangle rectangle); 15 12 } -
trunk/sources/HeuristicLab.Visualization/LineChart.Designer.cs
r1240 r1249 42 42 this.canvasUI.Dock = System.Windows.Forms.DockStyle.Fill; 43 43 this.canvasUI.Location = new System.Drawing.Point(0, 0); 44 this.canvasUI.MouseEventListener = null;45 44 this.canvasUI.Name = "canvasUI"; 46 45 this.canvasUI.Size = new System.Drawing.Size(551, 373); … … 48 47 this.canvasUI.Text = "canvas"; 49 48 this.canvasUI.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.canvasUI1_MouseWheel); 50 this.canvasUI.MouseMove += new System.Windows.Forms.MouseEventHandler(this.canvas _MouseMove);49 this.canvasUI.MouseMove += new System.Windows.Forms.MouseEventHandler(this.canvasUI_MouseMove); 51 50 this.canvasUI.ContextMenuStripChanged += new System.EventHandler(this.optionsToolStripMenuItem_Click); 52 51 this.canvasUI.MouseDown += new System.Windows.Forms.MouseEventHandler(this.canvasUI1_MouseDown); 52 this.canvasUI.MouseUp += new System.Windows.Forms.MouseEventHandler(this.canvasUI_MouseUp); 53 53 this.canvasUI.KeyDown += new System.Windows.Forms.KeyEventHandler(this.canvasUI1_KeyDown); 54 54 // -
trunk/sources/HeuristicLab.Visualization/LineChart.cs
r1244 r1249 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Diagnostics;4 3 using System.Drawing; 5 4 using System.Windows.Forms; … … 10 9 namespace HeuristicLab.Visualization { 11 10 public partial class LineChart : ViewBase { 12 internal class LinesShape : WorldShape {}13 11 private readonly IChartDataRowsModel model; 14 12 private readonly Canvas canvas; 15 13 16 14 private int maxDataRowCount; 17 private Boolean zoomFullView;18 15 private double minDataValue; 19 16 private double maxDataValue; 20 21 17 22 18 private readonly TextShape titleShape; … … 28 24 private readonly Grid grid; 29 25 30 private readonly WorldShape berni; 31 private readonly RectangleShape mousePointer; 26 private readonly Stack<RectangleD> clippingAreaHistory = new Stack<RectangleD>(); 27 private readonly WorldShape userInteractionShape; 28 private readonly RectangleShape rectangleShape; 29 private IMouseEventListener mouseEventListener; 30 private bool zoomToFullView; 32 31 33 32 /// <summary> … … 47 46 } 48 47 49 50 48 canvas = canvasUI.Canvas; 51 49 … … 71 69 canvas.AddShape(legendShape); 72 70 73 berni= new WorldShape();74 canvas.AddShape( berni);75 76 mousePointer = new RectangleShape(10, 10, 20, 20, Color.Black);77 berni.AddShape(mousePointer);71 userInteractionShape = new WorldShape(); 72 canvas.AddShape(userInteractionShape); 73 74 rectangleShape = new RectangleShape(0, 0, 0, 0, Color.Blue); 75 rectangleShape.Opacity = 50; 78 76 79 77 maxDataRowCount = 0; … … 85 83 86 84 //The whole data rows are shown per default 87 ResetView();85 ZoomToFullView(); 88 86 } 89 87 … … 103 101 canvasUI.Height); 104 102 105 berni.BoundingBox = linesShape.BoundingBox;106 berni.ClippingArea = new RectangleD(0, 0, berni.BoundingBox.Width, berni.BoundingBox.Height);103 userInteractionShape.BoundingBox = linesShape.BoundingBox; 104 userInteractionShape.ClippingArea = new RectangleD(0, 0, userInteractionShape.BoundingBox.Width, userInteractionShape.BoundingBox.Height); 107 105 108 106 grid.BoundingBox = linesShape.BoundingBox; … … 122 120 legendShape.ClippingArea = new RectangleD(0, 0, legendShape.BoundingBox.Width, 123 121 legendShape.BoundingBox.Height); 124 }125 126 public void ResetView() {127 zoomFullView = true;128 ZoomToFullView();129 130 canvasUI.Invalidate();131 122 } 132 123 … … 193 184 #endregion 194 185 195 private void ZoomToFullView() { 196 if (!zoomFullView) { 197 return; 198 } 199 var newClippingArea = new RectangleD(-0.1, 200 minDataValue - ((maxDataValue - minDataValue)*0.05), 201 maxDataRowCount - 0.9, 202 maxDataValue + ((maxDataValue - minDataValue)*0.05)); 203 204 SetLineClippingArea(newClippingArea); 205 historyStack.Push(newClippingArea); 186 public void ZoomToFullView() { 187 RectangleD newClippingArea = new RectangleD(-0.1, 188 minDataValue - ((maxDataValue - minDataValue)*0.05), 189 maxDataRowCount - 0.9, 190 maxDataValue + ((maxDataValue - minDataValue)*0.05)); 191 192 SetLineClippingArea(newClippingArea, true); 193 194 zoomToFullView = true; 206 195 } 207 196 … … 210 199 /// </summary> 211 200 /// <param name="clippingArea"></param> 212 private void SetLineClippingArea(RectangleD clippingArea) { 201 /// <param name="pushToHistoryStack"></param> 202 private void SetLineClippingArea(RectangleD clippingArea, bool pushToHistoryStack) { 203 zoomToFullView = false; 204 205 if (pushToHistoryStack) { 206 int count = clippingAreaHistory.Count; 207 208 if (count > 40) { 209 RectangleD[] clippingAreas = clippingAreaHistory.ToArray(); 210 clippingAreaHistory.Clear(); 211 212 for (int i = count - 20; i < count; i++) { 213 clippingAreaHistory.Push(clippingAreas[i]); 214 } 215 } 216 217 clippingAreaHistory.Push(clippingArea); 218 } 219 213 220 linesShape.ClippingArea = clippingArea; 214 221 … … 227 234 yAxis.BoundingBox.X2, 228 235 linesShape.ClippingArea.Y2); 236 237 canvasUI.Invalidate(); 229 238 } 230 239 … … 247 256 linesShape.AddShape(lineShape); 248 257 } 249 } 250 else { 258 } else { 251 259 for (int i = 1; i < row.Count; i++) { 252 260 var lineShape = new LineShape(i - 1, row[i - 1], i, row[i], row.Color, row.Thickness, row.Style); … … 260 268 //horizontalLineShape.YVal = maxDataValue; 261 269 rowToLineShapes[row] = lineShapes; 270 262 271 ZoomToFullView(); 263 264 canvasUI.Invalidate();265 272 } 266 273 … … 277 284 // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently. 278 285 linesShape.AddShape(lineShape); 279 } 280 else { 286 } else { 281 287 // lineShapes[0].X2 = maxDataRowCount; 282 288 lineShapes[0].Y1 = value; 283 289 lineShapes[0].Y2 = value; 284 290 } 285 } 286 else { 291 } else { 287 292 // horizontalLineShape.YVal = maxDataValue; 288 293 if (index > lineShapes.Count + 1) { … … 315 320 316 321 ZoomToFullView(); 317 canvasUI.Invalidate();318 322 } 319 323 … … 337 341 } 338 342 339 340 343 #region Begin-/EndUpdate 341 344 … … 362 365 #region Zooming / Panning 363 366 364 private readonly Stack<RectangleD> historyStack = new Stack<RectangleD>(); 365 private RectangleShape rectangleShape; 367 private void Pan(Point startPoint, Point endPoint) { 368 RectangleD clippingArea = CalcPanClippingArea(startPoint, endPoint); 369 SetLineClippingArea(clippingArea, false); 370 } 371 372 private void PanEnd(Point startPoint, Point endPoint) { 373 RectangleD clippingArea = CalcPanClippingArea(startPoint, endPoint); 374 SetLineClippingArea(clippingArea, true); 375 } 376 377 private RectangleD CalcPanClippingArea(Point startPoint, Point endPoint) { 378 return Translate.ClippingArea(startPoint, endPoint, linesShape.ClippingArea, linesShape.Viewport); 379 } 380 381 private void SetClippingArea(Rectangle rectangle) { 382 RectangleD clippingArea = Transform.ToWorld(rectangle, linesShape.Viewport, linesShape.ClippingArea); 383 384 SetLineClippingArea(clippingArea, true); 385 userInteractionShape.RemoveShape(rectangleShape); 386 } 387 388 private void DrawRectangle(Rectangle rectangle) { 389 rectangleShape.Rectangle = Transform.ToWorld(rectangle, userInteractionShape.Viewport, userInteractionShape.ClippingArea); 390 canvasUI.Invalidate(); 391 } 366 392 367 393 private void canvasUI1_KeyDown(object sender, KeyEventArgs e) { 368 if (e.KeyCode == Keys.Back && historyStack.Count > 1) { 369 historyStack.Pop(); 370 371 RectangleD clippingArea = historyStack.Peek(); 372 373 SetNewClippingArea(clippingArea); 374 canvasUI.Invalidate(); 394 if (e.KeyCode == Keys.Back && clippingAreaHistory.Count > 1) { 395 clippingAreaHistory.Pop(); 396 397 RectangleD clippingArea = clippingAreaHistory.Peek(); 398 399 SetLineClippingArea(clippingArea, false); 375 400 } 376 401 } … … 378 403 private void canvasUI1_MouseDown(object sender, MouseEventArgs e) { 379 404 Focus(); 405 380 406 if (e.Button == MouseButtons.Right) { 381 407 contextMenuStrip1.Show(PointToScreen(e.Location)); 382 } 383 else { 384 if (ModifierKeys == Keys.Control) { 385 CreateZoomListener(e); 386 } 387 else { 388 CreatePanListener(e); 389 } 390 } 391 } 392 393 private Point prevMousePosition = Point.Empty; 394 395 private void canvas_MouseMove(object sender, MouseEventArgs e) { 396 if (prevMousePosition != e.Location) { 397 prevMousePosition = e.Location; 398 399 double x = Transform.ToWorldX(e.X, berni.Viewport, berni.ClippingArea); 400 double y = Transform.ToWorldY(e.Y, berni.Viewport, berni.ClippingArea); 401 402 mousePointer.Rectangle = new RectangleD(x - 1, y - 1, x + 1, y + 1); 403 canvasUI.Invalidate(); 404 } 408 } else if (e.Button == MouseButtons.Left) { 409 if (ModifierKeys == Keys.None) { 410 PanListener panListener = new PanListener(e.Location); 411 panListener.Pan += Pan; 412 panListener.PanEnd += PanEnd; 413 414 mouseEventListener = panListener; 415 } else if (ModifierKeys == Keys.Control) { 416 ZoomListener zoomListener = new ZoomListener(e.Location); 417 zoomListener.DrawRectangle += DrawRectangle; 418 zoomListener.SetClippingArea += SetClippingArea; 419 420 rectangleShape.Rectangle = RectangleD.Empty; 421 userInteractionShape.AddShape(rectangleShape); 422 423 mouseEventListener = zoomListener; 424 } 425 } 426 } 427 428 private void canvasUI_MouseMove(object sender, MouseEventArgs e) { 429 if (mouseEventListener != null) { 430 mouseEventListener.MouseMove(sender, e); 431 } 432 } 433 434 private void canvasUI_MouseUp(object sender, MouseEventArgs e) { 435 if (mouseEventListener != null) { 436 mouseEventListener.MouseUp(sender, e); 437 } 438 439 mouseEventListener = null; 405 440 } 406 441 … … 411 446 RectangleD clippingArea = ZoomListener.ZoomClippingArea(linesShape.ClippingArea, zoomFactor); 412 447 413 SetLineClippingArea(clippingArea); 414 canvasUI.Invalidate(); 415 } 416 } 417 418 private void CreateZoomListener(MouseEventArgs e) { 419 var zoomListener = new ZoomListener(e.Location); 420 zoomListener.DrawRectangle += DrawRectangle; 421 zoomListener.OnMouseUp += OnZoom_MouseUp; 422 423 canvasUI.MouseEventListener = zoomListener; 424 425 rectangleShape = new RectangleShape(e.X, e.Y, e.X, e.Y, Color.Blue); 426 rectangleShape.Opacity = 50; 427 428 linesShape.AddShape(rectangleShape); 429 } 430 431 private void OnZoom_MouseUp(object sender, MouseEventArgs e) { 432 canvasUI.MouseEventListener = null; 433 434 RectangleD clippingArea = rectangleShape.Rectangle; 435 436 SetLineClippingArea(clippingArea); 437 historyStack.Push(clippingArea); 438 439 linesShape.RemoveShape(rectangleShape); 440 441 zoomFullView = false; //user wants to zoom => no full view 442 443 canvasUI.Invalidate(); 444 } 445 446 private void DrawRectangle(Rectangle rectangle) { 447 rectangleShape.Rectangle = Transform.ToWorld(rectangle, canvasUI.ClientRectangle, linesShape.ClippingArea); 448 canvasUI.Invalidate(); 449 } 450 451 private void CreatePanListener(MouseEventArgs e) { 452 PanListener panListener = new PanListener(canvasUI.ClientRectangle, linesShape.ClippingArea, e.Location); 453 454 panListener.SetNewClippingArea += SetNewClippingArea; 455 panListener.OnMouseUp += delegate { 456 historyStack.Push(linesShape.ClippingArea); 457 canvasUI.MouseEventListener = null; 458 }; 459 460 canvasUI.MouseEventListener = panListener; 461 } 462 463 private void SetNewClippingArea(RectangleD newClippingArea) { 464 SetLineClippingArea(newClippingArea); 465 466 zoomFullView = false; 467 canvasUI.Invalidate(); 448 SetLineClippingArea(clippingArea, true); 449 } 468 450 } 469 451 470 452 #endregion 471 453 472 454 #region Nested type: LinesShape 455 456 internal class LinesShape : WorldShape {} 457 458 #endregion 473 459 } 474 460 } -
trunk/sources/HeuristicLab.Visualization/PanListener.cs
r1055 r1249 4 4 namespace HeuristicLab.Visualization { 5 5 public class PanListener : IMouseEventListener { 6 private readonly Rectangle viewPort; 7 private readonly RectangleD clippingArea; 8 private readonly Point startPoint; 6 private Point startPoint; 9 7 10 public PanListener(Rectangle viewPort, RectangleD clippingArea, Point startPoint) { 11 this.viewPort = viewPort; 12 this.clippingArea = clippingArea; 8 public event MoveHandler Pan; 9 public event MoveHandler PanEnd; 10 11 public PanListener(Point startPoint) { 13 12 this.startPoint = startPoint; 14 13 } … … 16 15 #region IMouseEventListener Members 17 16 18 public event SetNewClippingAreaHandler SetNewClippingArea;19 public event MouseEventHandler OnMouseMove;20 public event MouseEventHandler OnMouseUp;21 22 17 public void MouseMove(object sender, MouseEventArgs e) { 23 PointD worldStartPoint = Transform.ToWorld(startPoint, viewPort, clippingArea); 24 PointD worldActualPoint = Transform.ToWorld(e.Location, viewPort, clippingArea); 25 26 double xDiff = worldActualPoint.X - worldStartPoint.X; 27 double yDiff = worldActualPoint.Y - worldStartPoint.Y; 28 29 RectangleD newClippingArea = new RectangleD(); 30 newClippingArea.X1 = clippingArea.X1 - xDiff; 31 newClippingArea.X2 = clippingArea.X2 - xDiff; 32 newClippingArea.Y1 = clippingArea.Y1 - yDiff; 33 newClippingArea.Y2 = clippingArea.Y2 - yDiff; 34 35 if (SetNewClippingArea != null) { 36 SetNewClippingArea(newClippingArea); 18 if (Pan != null) { 19 Pan(startPoint, e.Location); 37 20 } 38 21 39 if (OnMouseMove != null) { 40 OnMouseMove(sender, e); 41 } 22 startPoint = e.Location; 42 23 } 43 24 44 25 public void MouseUp(object sender, MouseEventArgs e) { 45 if (OnMouseUp!= null) {46 OnMouseUp(sender, e);26 if(PanEnd != null) { 27 PanEnd(startPoint, e.Location); 47 28 } 48 29 } -
trunk/sources/HeuristicLab.Visualization/ZoomListener.cs
r1058 r1249 6 6 private readonly Point startPoint; 7 7 8 public event DrawRectangleHandler DrawRectangle; 8 public event RectangleHandler DrawRectangle; 9 public event RectangleHandler SetClippingArea; 9 10 10 11 public ZoomListener(Point startPoint) { … … 14 15 #region IMouseEventListener Members 15 16 16 public event MouseEventHandler OnMouseMove;17 public event MouseEventHandler OnMouseUp;18 19 17 public void MouseMove(object sender, MouseEventArgs e) { 20 Rectangle r = new Rectangle();21 Point actualPoint = e.Location;22 23 if (startPoint.X < actualPoint.X) {24 r.X = startPoint.X;25 r.Width = actualPoint.X - startPoint.X;26 } else {27 r.X = actualPoint.X;28 r.Width = startPoint.X - actualPoint.X;29 }30 31 if (startPoint.Y < actualPoint.Y) {32 r.Y = startPoint.Y;33 r.Height = actualPoint.Y - startPoint.Y;34 } else {35 r.Y = actualPoint.Y;36 r.Height = startPoint.Y - actualPoint.Y;37 }38 39 18 if(DrawRectangle != null) { 40 DrawRectangle(r); 41 } 42 43 if (OnMouseMove != null) { 44 OnMouseMove(sender, e); 19 DrawRectangle(CalcRectangle(e.Location)); 45 20 } 46 21 } 47 22 48 23 public void MouseUp(object sender, MouseEventArgs e) { 49 if (OnMouseUp!= null) {50 OnMouseUp(sender, e);51 24 if(SetClippingArea != null) { 25 SetClippingArea(CalcRectangle(e.Location)); 26 } 52 27 } 53 28 54 29 #endregion 30 31 private Rectangle CalcRectangle(Point actualPoint) { 32 Rectangle rectangle = new Rectangle(); 33 34 if (startPoint.X < actualPoint.X) { 35 rectangle.X = startPoint.X; 36 rectangle.Width = actualPoint.X - startPoint.X; 37 } else { 38 rectangle.X = actualPoint.X; 39 rectangle.Width = startPoint.X - actualPoint.X; 40 } 41 42 if (startPoint.Y < actualPoint.Y) { 43 rectangle.Y = startPoint.Y; 44 rectangle.Height = actualPoint.Y - startPoint.Y; 45 } else { 46 rectangle.Y = actualPoint.Y; 47 rectangle.Height = startPoint.Y - actualPoint.Y; 48 } 49 50 return rectangle; 51 } 55 52 56 53 public static RectangleD ZoomClippingArea(RectangleD clippingArea, double zoomFactor) {
Note: See TracChangeset
for help on using the changeset viewer.