Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Problem with diagram and client area (Read 9701 times)
ayushneema
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 37
Joined: Sep 23rd, 2009
Problem with diagram and client area
Sep 30th, 2009 at 2:05pm
Print Post  
Hi,
I have sent you a sample application. i am facing following problem:
1. I want that when i start application my Diagram should cover entire client area

2.scrollbar position should be at center of the diagram so that zoom in/out can be done from the center.

Thanks
Ayush Neema

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with diagram and client area
Reply #1 - Sep 30th, 2009 at 3:46pm
Print Post  
Code
Select All
void Window1_Loaded(object sender, RoutedEventArgs e)
{
	scrollViewer.HorizontalContentAlignment = HorizontalAlignment.Center;
	scrollViewer.VerticalContentAlignment = VerticalAlignment.Center;

	diagram.ResizeToFitItems(5);
	diagram.ZoomToFit();
}

void diagram_MouseWheel(object sender, MouseWheelEventArgs e)
{
	e.Handled = true;
	Point point = e.GetPosition(diagram.Parent as ScrollViewer);
	Point oldCursorPosition = diagram.ClientToDoc(point);
	double newScrollX = diagram.ScrollX;
	double newScrollY = diagram.ScrollY;
	diagram.ZoomFactor = Math.Max(10, diagram.ZoomFactor + e.Delta / 60);

	Point newcurpos = diagram.ClientToDoc(e.GetPosition(diagram.Parent as ScrollViewer));
	double diffx = (oldCursorPosition.X - newcurpos.X);
	double diffy = (oldCursorPosition.Y - newcurpos.Y);
	newScrollX += diffx;
	newScrollY += diffy;

	diagram.ScrollTo(new Point(newScrollX, newScrollY));
} 

  
Back to top
 
IP Logged
 
ayushneema
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 37
Joined: Sep 23rd, 2009
Re: Problem with diagram and client area
Reply #2 - Oct 1st, 2009 at 4:05am
Print Post  
Hi Stoyo,
thanks for quick replay. but  i want that when i start application my Diagram should cover entire client area.
Right now when i start the application diagram apppear as a strip on the center of the client and rest of the area of client remain blank.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with diagram and client area
Reply #3 - Oct 1st, 2009 at 8:04am
Print Post  
If you set the Width/Height ratio of diagram.Bounds to be the same as the ActualWidth/ActualHeight ratio of the ScrollViewer, the diagram will fit perfectly in the ScrollViewer area after calling ZoomToFit.

double ratio = scrollViewer.ActualWidth / scrollViewer.ActualHeight;
double newDiagWidth = diagram.Bounds.Height / ratio;
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Problem with diagram and client area
Reply #4 - Oct 1st, 2009 at 1:53pm
Print Post  
Hi Stoyan,

We have tried this as well. Now it is covering entire client area but in a special case behavior is still not good.

If there are large no of nodes in a line (Horizontal or Vertical) then on zooming all nodes is moving to left (In case of vertical line)

How we can get zooming from center in this case. I am sending a sample image at your support id for that vertical alignment. Please have a look at it and suggest what we could do to get the desired result?

Regards,
Anshul
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with diagram and client area
Reply #5 - Oct 2nd, 2009 at 8:17am
Print Post  
Are you only setting Bounds.Width to the new width? With this the nodes will remain on the left side of the diagram. You could find the difference between the new width and the old one, and set diagram.Bounds = new Rect(oldBounds.X - difference / 2, oldBounds.Y, oldBounds.Width + difference, oldBounds.Height). Then the nodes should remain in the center of the new diagram area.

Stoyan
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Problem with diagram and client area
Reply #6 - Oct 2nd, 2009 at 10:52am
Print Post  
Thanks stoyan for the suggestion.

We are getting nodes in the middle but the problem is that if in this arrangement we do zoom-in/zoom-out all nodes moves to left side. We want same arrangement in zoom-in/zoom-out as well.

Regards,
Anshul
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Problem with diagram and client area
Reply #7 - Oct 2nd, 2009 at 11:29am
Print Post  
Hi Stoyan,

We have applied the same code at the end of Diagram_mouseWheel code from where we are performing zooming but in this case diagram is at the center and all the nodes at the left. Is it possible that all the nodes move away from the diagram?

We are sending a snap shot of it. Please have a look and suggest us with your valuable suggestion.


Regards,
Anshul
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with diagram and client area
Reply #8 - Oct 5th, 2009 at 6:36am
Print Post  
Code
Select All
Rect newBounds = diagram.ClientToDoc(
	new Rect(0, 0, scrollViewer.ActualWidth, scrollViewer.ActualHeight)); 



This code in your SetZoom method grows the diagram to the right while keeping it centered, so the nodes seem to move to the left. You could get just the size from this rect, find its difference from the current diagram.Bounds.Size, and use the Rect.Inflate method to add the difference to all sides of diagram.Bounds, instead of the Union method you are using now.
  
Back to top
 
IP Logged
 
ayushneema
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 37
Joined: Sep 23rd, 2009
Re: Problem with diagram and client area
Reply #9 - Oct 5th, 2009 at 9:46am
Print Post  
Hi stoyo
Thanks for replay,
now i am able to set my nodes at the center of the diagram and perform zoom -in/ out on them.
but i am facing problem to set the position of horizontal scroll bar. i want to set it at the middle of the bar. Although i am setting the position but it is not working.
i sent you the sample code. i am setting the position in at the end of setzoom method.
please suggest me.
Thanks
Ayush neema
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with diagram and client area
Reply #10 - Oct 6th, 2009 at 6:23am
Print Post  
There are a couple of things wrong now in SetZoom. First the Rect constructor throws an exception when the width or height arguments are negative, which happens when you calculate the difference, and you just catch and ignore the exception. Another problem is that Rect is a value type, and diagram.Bounds returns a value in the local execution stack rather than a reference to the actual Bounds rectangle, so diagram.Bounds.Inflate() grows the stack value but does not change  diagram.Bounds. Assuming you need Bounds only to grow, you could do that like this:

Code
Select All
double sizeDX = newBounds.Size.Width - currentDiagramSize.Width;
if (sizeDX < 0)
	sizeDX = 0;

double sizeDY = newBounds.Size.Height - currentDiagramSize.Height;
if (sizeDY < 0)
	sizeDY = 0;

Rect diagBounds = diagram.Bounds;
diagBounds.Inflate(sizeDX, sizeDY);
diagram.Bounds = diagBounds;
 


  
Back to top
 
IP Logged
 
ayushneema
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 37
Joined: Sep 23rd, 2009
Re: Problem with diagram and client area
Reply #11 - Oct 6th, 2009 at 3:05pm
Print Post  
Hi stoyon,
I did the need ful changes as per your suggesstion.
But still i am unable to set the position of horizontal scrollbar at the center. i need to set the horizontal scrollbar at the center of the diagram. so that it look like we are zooming towards center.
I have sent you the sample.
Thanks
Ayush Neema.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with diagram and client area
Reply #12 - Oct 8th, 2009 at 10:50am
Print Post  
Are you trying to preserve the diagram point that was at the center of the diagram visible area, so it remains there after zooming in/out? And at the same time, grow diagram.Bounds, so it fills the entire scroll viewer? The code below implements that.

Code
Select All
public void SetZoom(double percentage)
{
	Point oldCenter = scrollViewer.TransformToDescendant(diagram.DocumentPlane).Transform(
		new Point(scrollViewer.ActualWidth / 2, scrollViewer.ActualHeight / 2));

	percentage = Math.Max(10, Math.Min(200, percentage));
	diagram.ZoomFactor = percentage;

	Rect newBounds = diagram.ClientToDoc(
		new Rect(0, 0, scrollViewer.ActualWidth, scrollViewer.ActualHeight));
	Size currentDiagramSize = diagram.Bounds.Size;

	double sizeDX = newBounds.Size.Width - currentDiagramSize.Width;
	if (sizeDX < 0)
		sizeDX = 0;

	double sizeDY = newBounds.Size.Height - currentDiagramSize.Height;
	if (sizeDY < 0)
		sizeDY = 0;

	Rect diagBounds = diagram.Bounds;
	diagBounds.Inflate(sizeDX, sizeDY);
	diagram.Bounds = diagBounds;

	double newScrollX = oldCenter.X - newBounds.Width / 2;
	double newScrollY = oldCenter.Y - newBounds.Height / 2;

	diagram.ScrollTo(new Point(newScrollX, newScrollY));
}
 



If in the Loaded handler you initialize the column of nodes to be at the center of the viewer, the nodes should stay in the center of the scroll viewer when you call SetZoom from the MouseWheel handler.
  
Back to top
 
IP Logged
 
ayushneema
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 37
Joined: Sep 23rd, 2009
Re: Problem with diagram and client area
Reply #13 - Oct 8th, 2009 at 3:05pm
Print Post  
Hi Stoyan
thanks for your valuable suggestion.

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