Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic When to set default Anchor Pattern (Read 7258 times)
Al
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Sep 3rd, 2014
When to set default Anchor Pattern
Sep 4th, 2014 at 9:33am
Print Post  
Hi, I am using the built-in anchor point definition but still my links join in strange places on the shapes (do not adhere to the Anchor pattern)

Code (Javascript)
Select All
var decision1In3Out = MindFusion.Diagramming.AnchorPattern.fromId("Decision1In3Out");
diagramNode.setAnchorPattern(decision1In3Out);
 



Create my links
Code (Javascript)
Select All
                var newLink = diagram.getFactory().createDiagramLink(
                    nodeMap[link.origin],
                    nodeMap[link.target]);
                newLink.setShape(2);
                newLink.route(true);
 



I then do a layered layout and re-route my links

Code (Javascript)
Select All
            diagram.arrange(layout);

            diagram.routeAllLinks();
 



Is there a problem with order that I am doing things?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: When to set default Anchor Pattern
Reply #1 - Sep 4th, 2014 at 10:41am
Print Post  
Try setting layout.anchoring = MindFusion.Graphs.Anchoring.Reassign;

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


I Love MindFusion!

Posts: 56
Joined: Sep 3rd, 2014
Re: When to set default Anchor Pattern
Reply #2 - Sep 4th, 2014 at 11:25am
Print Post  
Thanks Stoyan, I tried setting layout.anchoring, now my links go into the decisions properly but I still have link going in to the bottom of Rectangles and out the top of decisions (img attached). Here is my pseudo code:

Code (Javascript)
Select All
var decision1In3Out = MindFusion.Diagramming.AnchorPattern.fromId("Decision1In3Out");
var topInBottomOut = MindFusion.Diagramming.AnchorPattern.fromId("TopInBottomOut");

var diagramNode = diagram.getFactory.createShapeNode(bounds);
diagramNode.setShape('Rectangle');
diagramNode.setAnchorPattern(topInBottomOut);

var diagramNode = diagram.getFactory.createShapeNode(bounds);
diagramNode.setShape('Decision');
diagramNode.setAnchorPattern(decision1In3Out);


var newLink = diagram.getFactory().createDiagramLink(
	nodeMap[link.origin],
        nodeMap[link.target]);
newLink.setShape(2);
newLink.route(true);


var layout = new MindFusion.Graphs.LayeredLayout();
layout.nodeDistance = 10;
layout.layerDistance = 10;
layout.anchoring = MindFusion.Graphs.Anchoring.Reassign;

diagram.arrange(layout);
diagram.routeAllLinks();
 

  

Untitled_007.png ( 192 KB | 300 Downloads )
Untitled_007.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: When to set default Anchor Pattern
Reply #3 - Sep 4th, 2014 at 2:05pm
Print Post  
If you are using the arrange() method both on containers and the overall diagram, the links between children of different containers might be ignored. Try running this code from a loop for all links before calling routeAllLinks:

Code
Select All
var oanchor = link.origin.getNearestAnchor(link.points[0], link, false);
var danchor = link.destination.getNearestAnchor(link.points[link.points.length - 1], link, true);
link.setOriginAnchor(oanchor.index);
link.setDestinationAnchor(danchor.index); 



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


I Love MindFusion!

Posts: 56
Joined: Sep 3rd, 2014
Re: When to set default Anchor Pattern
Reply #4 - Sep 4th, 2014 at 3:04pm
Print Post  
Putting your code between '.arrange.' and '.routeAllLinks' sorts out the anchor points just fine but it now doesn't avoid existing shapes and just draws over them Smiley.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: When to set default Anchor Pattern
Reply #5 - Sep 4th, 2014 at 6:17pm
Print Post  
Check if there isn't some error shown in the JavaScript console. If it happens just before the code reaches the routeAllLinks call, you will see the anchor point connections but no link routes applied. This works fine in my test:

Code
Select All
for (var i = 0; i < diagram.links.length; i++)
{
	var link = diagram.links[i];
	var oanchor = link.origin.getNearestAnchor(link.points[0], link, false);
	var danchor = link.destination.getNearestAnchor(link.points[link.points.length - 1], link, true);
	link.setOriginAnchor(oanchor.index);
	link.setDestinationAnchor(danchor.index);
}
diagram.routeAllLinks(); 

  
Back to top
 
IP Logged
 
Al
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Sep 3rd, 2014
Re: When to set default Anchor Pattern
Reply #6 - Sep 5th, 2014 at 6:53am
Print Post  
Weirdest thing - I used your code as-is, no errors in the console, anchors are ok but the routing isn't.

Code (Javascript)
Select All
            //Layout all container nodes
            for (index = 0; index < containerNodes.length; ++index) {
                var containerNode = containerNodes[index];
                containerNode.arrange(layout);  //This resizes the container
            }

            diagram.arrange(layout);

            //Ensure that anchors on shapes in different containers obey the anchor pattern specified
            for (var i = 0; i < diagram.links.length; i++)
            {
                var link = diagram.links[i];
                var oanchor = link.origin.getNearestAnchor(link.points[0], link, false);
                var danchor = link.destination.getNearestAnchor(link.points[link.points.length - 1], link, true);
                link.setOriginAnchor(oanchor.index);
                link.setDestinationAnchor(danchor.index);
            }

            diagram.routeAllLinks();
 




  

Untitled_008.png ( 39 KB | 193 Downloads )
Untitled_008.png
Back to top
 
IP Logged
 
Al
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Sep 3rd, 2014
Re: When to set default Anchor Pattern
Reply #7 - Sep 5th, 2014 at 6:54am
Print Post  
Maybe you could post your test project so I can check all the other settings you're using?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: When to set default Anchor Pattern
Reply #8 - Sep 5th, 2014 at 8:06am
Print Post  
You can find my test page attached. If there's only one link not routed correctly as in the image, it's possible that the routing algorithm failed to find a path around that specific node. Check if it will work better if you run LayeredLayout with larger node and layer distances, or call diagram.setRouteMargin() with a smaller value than the default 8 mm before calling routeAll.

I hope that helps,
Stoyan
  

routing_test.zip (Attachment deleted)
Back to top
 
IP Logged
 
Al
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Sep 3rd, 2014
Re: When to set default Anchor Pattern
Reply #9 - Sep 5th, 2014 at 1:52pm
Print Post  
Thanks Stoyan, I have actually stopped using diagram.arrange because it no longer suited my drawing so the settings for layered layout spacing are not being used (although the problem still exists).
I tried setRouteMargin and the results were slightly better, I thinkI will just accept that there is only so far auto-routing can go Smiley.

Thanks for all your help, I am doing a POC before purchasing the component and my diagram is really coming on nicely so am pretty sure that we will go with your product very soon.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint