Den onsdag 9 mars 2016 kl. 20:15:22 UTC+1 skrev jonas.t...@gmail.com:
> My new idea to untangle the links is simply to swap theiry positions.
> But there muste be something wrong with my logic.
>
> The circle function will attempt draw out the *nodes* in circle from lowest node to higest.
>
> 0 NODE Links-> 2,3
> 1 NODE Links-> 3,4
> 2 NODE Links-> 0,4
> 3 NODE Links-> 0,1
> 4 NODE Links-> 1,2
>
> As you may guess the links come out criss crossed.
> But i was thinking if node 0 draw it first link to node 2.
> Then i can interchange the cordinates of node 2 and node 0+1 "that is i+1" to move node segment 2 next to i.
>
> So now i have the tempnode in memory and that will have one link point back j=0;
> And one link point forward. That link should be exchanged with i+1. Because we are in next round of loop. I think the logic is straightforward so i can't see why it is not working. Swap cordinates of random with i+1 it should work.
>
> function untangle_links(){
>
> j=0;
> tempnode=0;
> for(var i=0;i<nodes.length-1;i++){
> tempnode=arr[tempnode].nodelinks[j];
> tempX=arr[tempnode].rposX;
> tempY=arr[tempnode].rposY;
> arr[tempnode].rposX=arr[i+1].rposX;
> arr[tempnode].rposY=arr[i+1].rposY;
> arr[i+1].rposX=tempX;
> arr[i+1].rposY=tempY;
> j=1;
> }
> }
The principle seem sound but i think i need to make a list for what nodes that have been drawn to, that sure will be beneficial when there is more links than two at each node.