Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) ZoomToRect, ZoomToFit ignore negative X, Y ? (Read 8015 times)
ulthien
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 91
Location: Munich
Joined: Nov 29th, 2011
ZoomToRect, ZoomToFit ignore negative X, Y ?
Dec 17th, 2012 at 3:52pm
Print Post  
The user can push a node by dragging it to stick a bit into the negative X or Y (left of, or upwards) of the visible viewport. Such a node is only half-shown in the diagram.

I have built a little toolbar button endowed with the function "fit to view" in which i do a union of nodes' sizes, with the intention to ZoomToRect.

e.g.

foreach (DiagramNode c in Diagram.Nodes)
{
if (c is MyVisual && c.Visible)
{
sizeup.Union(c.Bounds);
}
}
Diagram.ZoomToRect(sizeup);

which works nice UNLESS the node sticks e.g. left bit outside the (scrollviewer endowed) viewport, in which case it zoomsTo only from 0,0 and leaves the half-shown node outside.

____

I also tried using the Diagram.ZoomToFit() but it looks like this method also ignores the negative values of the nodes i.e. nodes sticking atop or to left out of viewport.

Any idea how to snap to Rect that is beginning bit to left or above the 0 ?


cheers
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ZoomToRect, ZoomToFit ignore negative X, Y ?
Reply #1 - Dec 17th, 2012 at 6:26pm
Print Post  
ZoomToRect also changes the diagram's scroll position, but the ScrollViewer won't allow scrolling if the rectangle you specify is not contained within diagram.Bounds. So you must also assign to diagram.Bounds a rectangle that contains the union of all nodes, e.g. call ResizeToFitItems to calculate and set it automatically.

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


I love YaBB 1G - SP1!

Posts: 91
Location: Munich
Joined: Nov 29th, 2011
Re: ZoomToRect, ZoomToFit ignore negative X, Y ?
Reply #2 - Dec 18th, 2012 at 10:55am
Print Post  
Thank you!

actually then, 3 little lines do the job:

            Diagram.Bounds = sizeup;
            //resize with gap of 40 px & only visible items
            Diagram.ResizeToFitItems(40.0, true);
            Diagram.ZoomToFit();
  
Back to top
 
IP Logged
 
ulthien
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 91
Location: Munich
Joined: Nov 29th, 2011
Re: ZoomToRect, ZoomToFit ignore negative X, Y ?
Reply #3 - Jan 29th, 2013 at 12:05pm
Print Post  
Actually, related to this - is there a simple way to update scrollviewers once the user drags the node(s) out to the minus area of diagram boundaries?

if he drags to right and down, the scrollviewers update, but not in negative direction.

Would assigning the new union to boundaries help? (resize to fit would change his zoom factor abruptly..)
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ZoomToRect, ZoomToFit ignore negative X, Y ?
Reply #4 - Jan 29th, 2013 at 12:15pm
Print Post  
If you mean the auto-resize feature, it sounds as you have set AutoResize to RightAndDown; set it to AllDirections instead.

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


I love YaBB 1G - SP1!

Posts: 91
Location: Munich
Joined: Nov 29th, 2011
Re: ZoomToRect, ZoomToFit ignore negative X, Y ?
Reply #5 - Jan 29th, 2013 at 1:25pm
Print Post  
Thank you Stoyo Smiley that was it

you are really a remedy for the SoS syndrome (Stressed oldDeveloper State)


cheers
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ZoomToRect, ZoomToFit ignore negative X, Y ?
Reply #6 - Jan 29th, 2013 at 1:41pm
Print Post  
Smiley
  
Back to top
 
IP Logged
 
ulthien
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 91
Location: Munich
Joined: Nov 29th, 2011
Re: ZoomToRect, ZoomToFit ignore negative X, Y ?
Reply #7 - Feb 22nd, 2013 at 5:43pm
Print Post  
is there a simple way to stretch the diagram bounds to be exact the scrollviewer dimensions after a zoomtofit?

i.e. how to fill whole 2D space inside the scrollviewer at all times with the diagram?

cheers
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ZoomToRect, ZoomToFit ignore negative X, Y ?
Reply #8 - Feb 25th, 2013 at 7:46am
Print Post  
Try this:

Code
Select All
private void OnDiagramZoomFill(object sender, RoutedEventArgs e)
{
	var diagBounds = diagram.Bounds;
	diagram.ZoomToFit();

	var viewerRect = new Rect(0, 0,
		scrollViewer.ActualWidth,
		scrollViewer.ActualHeight);
	viewerRect = diagram.ClientToDoc(viewerRect);

	var dx = viewerRect.Width > diagBounds.Width ?
		(viewerRect.Width - diagBounds.Width) / 2 : 0;
	var dy = viewerRect.Height > diagBounds.Height ?
		(viewerRect.Height - diagBounds.Height) / 2 : 0;

	diagBounds.Inflate(dx, dy);
	diagram.Bounds = diagBounds;
} 



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


I love YaBB 1G - SP1!

Posts: 91
Location: Munich
Joined: Nov 29th, 2011
Re: ZoomToRect, ZoomToFit ignore negative X, Y ?
Reply #9 - Feb 25th, 2013 at 10:57am
Print Post  
seems to work well, thank you!
  
Back to top
 
IP Logged
 
ulthien
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 91
Location: Munich
Joined: Nov 29th, 2011
Re: ZoomToRect, ZoomToFit ignore negative X, Y ?
Reply #10 - Feb 26th, 2013 at 1:31pm
Print Post  
i also added a derivate function/method segment of the one above, that trims the scrollviewer back to diagram size, so it does not get wildly oversized through zooming/moving nodes around:

Code
Select All
            SequenceVisualDiagram.ResizeToFitItems(0.0, true);
            var viewerRect = new Rect(0, 0,
                             ScrollV.ActualWidth,
                             ScrollV.ActualHeight);
            viewerRect = SequenceVisualDiagram.ClientToDoc(viewerRect);
            Log.Debug("diag trim..");
            SequenceVisualDiagram.Bounds = viewerRect; 



that one i bound to "resize to fit" toolbar button that centers all nodes & trims down the scrollviewer i.e. diagram size.

  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint