Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly align nodes with multiple parents

Here's the screenshot

Space tree

I’ve been dealing with this problem and tried to modify the Y position without any luck. Notice that Meli Job B seems to be misaligned. This only happens if the parent box is attached to multiple parents. I tried the code below to know if a box have multiple parents but I can’t work on how I will position the Y-axis as they all fall in the same place.

Code:

var pos = node.getPos();
var parents = node.getParents();
if(parents.length > 1) {
    var subnodes = node.getSubnodes();
    for(var i=0; i<subnodes.length; i++) {
        var yPos = subnodes[i].getPos();
        yPos.y = pos.y;
    }
}

Thanks in advance for help.

like image 954
proxies Avatar asked Nov 29 '12 08:11

proxies


Video Answer


1 Answers

var pos = node.getPos();
var parents = node.getParents();
var subnodes = node.getSubnodes();
for(var i=0; i<subnodes.length; i++) 
{
    var yPos = subnodes[i].getPos();
    if(parents.length > 1) 
        yPos.y = pos.y;
    else
        yPos.y = 0
}
like image 174
Tarek Avatar answered Sep 18 '22 03:09

Tarek