Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ResizeToFitItems() with no Layout (Read 2089 times)
Joel D.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 41
Location: Vancouver, Canada
Joined: Feb 6th, 2017
ResizeToFitItems() with no Layout
Jun 1st, 2018 at 3:28pm
Print Post  
Hi,

I have a diagram that is not using any automatic layout; the user can drop nodes onto the canvas and move them wherever they want.

I would like to call ResizeToFitItems(10.0) every once in a while so that the canvas is only as large as is necessary, however this makes the nodes move to the top-left (or the center, if I set the diagram alignment as center).

Is there a way to have the nodes not move their position, and have ResizeToFitItems() only crop to the right and bottom of the nodes?

Thanks,
Joel.
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: ResizeToFitItems() with no Layout
Reply #1 - Jun 4th, 2018 at 11:34am
Print Post  
Hi,

You can try to achieve this behavior by taking the content bounding rectangle and use that as the new diagram bounds, and maybe apply margins if needed, something like:

Code
Select All
var bounds = diagram.GetContentBounds(true, false);
bounds.Width += 10;
bounds.Height += 10;
diagram.Bounds = bounds; 



Note that setting the diagram.AutoResize property to AutoResize.RightAndDown can achieve that for interactively drawn items.

Regards,
Lyubo
  
Back to top
 
IP Logged
 
Joel D.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 41
Location: Vancouver, Canada
Joined: Feb 6th, 2017
Re: ResizeToFitItems() with no Layout
Reply #2 - Jun 6th, 2018 at 12:08am
Print Post  
AutoResize with RightAndDown will automatically expand the diagram to the right and down if I move a node rightward and downward. However, if I move the node back to its original location, the diagram does not contract in size; it stays at the new larger size.

I have used your code example, though, combined with a Rect.Union with the scrollviewer's viewport width and height, and I think I'm getting better results.

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