Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Ability to zoom in to any point within the diagram container (Read 3242 times)
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Aug 5th, 2014
Ability to zoom in to any point within the diagram container
Aug 5th, 2014 at 3:27pm
Print Post  
Hi,

First of all, thanks for the great diagramming components!

I added a MouseWheel event handler to diagram to zoom it in and out with mouse wheel + Ctrl. Using diagram.SetZoomFactor(). The problem is that when a small diagram in the center, and its scroll bars are disabled and stretched to fit the window, it is necessary to aim precisely to it. Is it possible to make it work not only in the area of ​​the diagram, but also at any point within its container (where are the scrollbars)?

Thanks,
-Kostya
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Ability to zoom in to any point within the diagram container
Reply #1 - Aug 5th, 2014 at 3:50pm
Print Post  
Hi,

Thank you too! You could handle the PreviewMouseWheel event on the ScrollViewer itself, instead of diagram's MouseWheel:

Code
Select All
<ScrollViewer
	PreviewMouseWheel="OnMouseWheel" ...

private void OnMouseWheel(object sender, MouseWheelEventArgs e)
{
	Debug.WriteLine(e.GetPosition(diagram.DocumentPlane));
	e.Handled = true;
} 



Alternatively handle MouseWheel on both the diagram and the ScrollViewer. Then you will get the diagram event raised when mouse points inside diagram's area and the viewer's when it points outside.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Aug 5th, 2014
Re: Ability to zoom in to any point within the diagram container
Reply #2 - Aug 6th, 2014 at 11:53am
Print Post  
Hi Stoyan,

Thank you, it works! But the very desirable thing outside the diagram area is a panning using Alt. Is it possible to stretch/auto-size the diagram area within its ScrollViewer to make zoom/pan always work without additional tricks? Or the only way is to add a handler(s), like you wrote above for zoom, to be able to use pan there too?

The problem is that if even to set the diagram bounds, say, to 5000x5000 (so on any zoom value it will be larger than its container), the diagram willn't be centered but at the left top corner of this huge canvas. So the current behavior is good, except for the absence panning around the diagram area.

Thanks,
-Kostya
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Ability to zoom in to any point within the diagram container
Reply #3 - Aug 6th, 2014 at 2:09pm
Print Post  
Hi Kostya,

ScrollViewer does not allow scrolling when it's larger than its contents, so you won't be able to pan with smaller diagram even if you forward the viewer's mouse events to the diagram to handle panning. Instead, you could make diagram.Bounds bigger when zooming out and fix scroll position to ensure the diagram stay centered at the mouse location instead of converging to top-left of the viewer:

Code
Select All
private void OnCtrMouseWheel(object sender, MouseWheelEventArgs e)
{
	var docPos = e.GetPosition(diagram.DocumentPlane);
	diagram.SetZoomFactor(
		Math.Max(5, diagram.ZoomFactor + e.Delta / 50.0),
		docPos);
	scrollViewer.UpdateLayout();

	var viewerDocBounds = diagram.Viewport;
	if (!diagram.Bounds.Contains(viewerDocBounds))
	{
		diagram.Bounds = Rect.Union(viewerDocBounds, diagram.Bounds);
		scrollViewer.UpdateLayout();
	}
	var newDocPos = e.GetPosition(diagram.DocumentPlane);
	var newScrollX = diagram.ScrollX + docPos.X - newDocPos.X;
	var newScrollY = diagram.ScrollY + docPos.Y - newDocPos.Y;
	if (newScrollX < diagram.Bounds.Left || newScrollY < diagram.Bounds.Top)
	{
		diagram.Bounds = Rect.Union(
			diagram.Bounds, new Point(newScrollX, newScrollY));
		diagram.ScrollX = newScrollX;
		diagram.ScrollY = newScrollY;
	}

	e.Handled = true;
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Aug 5th, 2014
Re: Ability to zoom in to any point within the diagram container
Reply #4 - Aug 7th, 2014 at 6:39am
Print Post  
Stoyan, thank you very much for your help! It's really the best solution as it solves all problems: zooming and panning  at any point.
-Kostya
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint