Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Issues with Composite Nodes in Tree Layout (Read 3429 times)
dhaval
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 5
Joined: Nov 15th, 2012
Issues with Composite Nodes in Tree Layout
Nov 26th, 2012 at 9:01pm
Print Post  
I am using bunch of Composite Nodes to generate a tree layout. But when I try draw links from a node in the lower level to a node in the upper level, the links overlap the nodes.

Refer to Overlaping_Composite_Nodes.png

Code (C++)
Select All
 _RootLayout  = new TreeLayout(
                _RootNode,
                TreeLayoutType.Cascading,
                false,
                TreeLayoutLinkType.Cascading2,
                TreeLayoutDirections.TopToBottom,
                5,
                5,
                true,
                new SizeF(10,10));

            if (_RootLayout != null)
            {
                _RootLayout.Arrange(Diagram);
            }
 




Is there a way this can be avoided?

One option that prevent this behavior is Diagram.RouteAllLinks();

But if I call this method after creating and arranging the tree layout, it messes up with other links and nodes.

Refer to RouteAllLinks.png

Code (C++)
Select All
 _RootLayout  = new TreeLayout(
                _RootNode,
                TreeLayoutType.Cascading,
                false,
                TreeLayoutLinkType.Cascading2,
                TreeLayoutDirections.TopToBottom,
                5,
                5,
                true,
                new SizeF(10,10));

            if (_RootLayout != null)
            {
                _RootLayout.Arrange(Diagram);
            }

            foreach (DiagramNode node in Diagram.Nodes)
            {
                Diagram.ResizeToFitItem(node);
            }

            //Diagram.RoutingOptions.TurnCost = 50;
            //Diagram.RoutingOptions.LengthCost = 50;
            //Diagram.RoutingOptions.CrossingCost = 50;

            Diagram.RouteAllLinks(); 



As you see, I have also tried setting the RoutingOptions for TurnCost, LengthCost and CrossingCost

Code to add link:
Code (C++)
Select All
 DiagramLink link = new DiagramLink(Diagram);
                    link.Origin = fromNode;
                    link.Destination = toNode;
                    link.AllowMoveEnd = false;
                    link.AllowMoveStart = false;
                    link.AutoSnapToNode = true;
                    link.BaseShape = ArrowHeads.Circle;
                    link.BaseShapeSize = 2;
                    link.AutoRoute = false;

                    Diagram.Links.Add(link); 



Is there a way I can achieve this without my links overlapping the nodes, and without the links being messed up.

« Last Edit: Nov 27th, 2012 at 10:25pm by dhaval »  

Overlaping_Composite_Nodes.png (Attachment deleted)
RouteAllLinks.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Issues with Composite Nodes in Tree Layout
Reply #1 - Nov 27th, 2012 at 6:51am
Print Post  
TreeLayout is really just for arranging trees, and after adding a back link, your graph is no longer a tree. For general graphs, try using LayeredLayout or OneWayLayout. If you prefer TreeLayout, you could still route back links by calling their Route() method after TreeLayout:

Code
Select All
foreach (DiagramLink link in diagram.Links)
	if (link.StartPoint.Y > link.EndPoint.Y)
		link.Route(); 



Regarding costs in RoutingOptions, they are considered only if you set diagram.LinkRouter = new GridRouter();

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
dhaval
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 5
Joined: Nov 15th, 2012
Re: Issues with Composite Nodes in Tree Layout
Reply #2 - Nov 28th, 2012 at 4:17am
Print Post  
Stoyo,

Thanks a lot for replying back. What you say makes sense for the second part of my question.

I guess you missed the first part of my question.

Here is what I an doing,
1. Creating a bunch of composite nodes, containing Text and Images.

2. Create a tree layout with these nodes. Everything works perfectly till this point.

3. Now, I try to create a link from one node to another
Code (C++)
Select All
DiagramLink link = new DiagramLink(tDiagram);
link.Origin = fromNode;
link.Destination = toNode;
link.AllowMoveEnd = false;
link.AllowMoveStart = false;
link.AutoSnapToNode = true;
link.BaseShape = ArrowHeads.Circle;
link.BaseShapeSize = 2;
link.AutoRoute = true;

Diagram.Links.Add(link);

link.Route(); 



When I do this, the link overlaps the composite node and anchors to the top of the composite node.

Please refer to the attachment.

So, I want to know if there is a way to avoid this overlap and anchor the link to the bottom of the composite node?
  

Overlaping_Composite_Nodes_001.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Issues with Composite Nodes in Tree Layout
Reply #3 - Nov 28th, 2012 at 6:59am
Print Post  
Hi,

Try calling link.UpdateIntersections() after setting Origin and Destination. If it still connects to the top of toNode, perhaps it has an AnchorPattern set with only one incoming point at top center? In such case, try adding second incoming anchor point at the bottom. You could also explicitly set the link's StartPoint and EndPoint properties to any coordinates you'd like.

You might also replace the assignments to Origin, Destination and calls to UpdateIntersections and Links.Add with a single call to Factory.CreateDiagramLink, i.e.

Code
Select All
DiagramLink link = diagram.Factory.CreateDiagramLink(fromNode, toNode);

// instead of

DiagramLink link = new DiagramLink(diagram);
link.Origin = toNode;
link.Destination = fromNode;
link.UpdateIntersections();
diagram.Links.Add(link); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
dhaval
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 5
Joined: Nov 15th, 2012
Re: Issues with Composite Nodes in Tree Layout
Reply #4 - Nov 29th, 2012 at 4:41am
Print Post  
Stoyo,
Thanks again for the reply. Using CreateDiagramLink worked like a charm for me.

However, I have a related questions. When I am creating a node I create an AnchorPattern

Code (C++)
Select All
 myCompositeNode.AnchorPattern = new AnchorPattern(new AnchorPoint[]
            {
                new AnchorPoint(50, 0, true, false), //Bottom Center
                new AnchorPoint(0, 50, true, false) //Left Center

            }); 



Now, when I create a link with this node as the destination, now do I specify which AnchorPoint should be used?

I tried doing:
Code (C++)
Select All
 DiagramLink link = myDiagram.Factory.CreateDiagramLink(parentNode, childNode);

link.DestinationAnchor = 1; 



The documentation about DestinationAnchor does not say much about. It just mentions it is the index of the AnchorPoint from the AnchorPattern.

In my case, if I want a link to anchor to the "Bottom Center" AnchorPoint, how do I achieve this?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Issues with Composite Nodes in Tree Layout
Reply #5 - Nov 29th, 2012 at 7:43am
Print Post  
Hi,

The index of your AnchorPoint with a // Bottom Center comment is 0, however the coordinates you pass to it make it the top center actually. These coordinates are specified as percentage of node size, so change the position from (50, 0) to (50, 100) to make it bottom center, or add a new AnchorPoint(50, 100) to the array. The index you assign to OriginAnchor or DestinationAnchor properties is the position of AnchorPoint elements within the array you pass to the AnchorPattern constructor.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint