Auto layout changing node order

I’m using GoWeb, and what i’m trying to do is build a flowchart so after a decision i have n branches of n nodes. I can add as many branches as i want as long as they each have 1 node in them and everything works fine. I can add 2+ nodes to the first branch(sequential flow not “either/or”) and the graph gets laid out fine.

my problem occurs when i have the first branch containing 1 node, and try to add a second branch containing 2+(again sequential nodes, i basically want multiple columns of things coming out of the decision) nodes. The autoLayout function takes my column of 2+ nodes and makes it the first (left most) branch, even though it was added second it moves the first branch i added(which has 1 node) to the right. So it appears in reverse horizontal order of how they were created. If i keep adding columns they keep getting added on the left. but when i add single node branches they get added to the right like i would expect.(1 2 3 4 5 instead of 5 4 3 2 1)
I have them bieng added and linked correctly, if i change certain properties (switching from sourceLinks.Last to sourceLinks.First) moves the new nodes in a manner that i would expect.
Also the single node branches always align with the bottom of the multi node branches. It doesnt bother me, but i didnt know if knowing that would help or not.
Any help would be appreciated, could it be some preference of the AutoLayout to make the graph look like its cascading by putting taller groups to the left?
John

I can’t see how the ordering of links matters.



What layout are you using, with what parameters?



Can you upload some screenshots? (use the post reply button at top of page to include images)

As far as i know i’m using the default layout. I started off by using the ChartViewer class from the Flowgrammer demo.

You cant see how it matters to me, or how it matters to the software? I only care because it will most likely confuse the users if the order isnt the same for all conditions.
The first step works fine.
i removed unimportant text and added lables just to make everything clear.
in this next image, i add a branch with 2 nodes, if i were to add a single node it would appear to the right of the first item, but since i added two nodes they show up to the left for some reason.
if it always added this way i wouldnt care, but it seems to shift where new nodes are added based on the number of them in the branch. When i add another single node branch it appears to the right of "first item added" like i think it should.
I hope this makes things easier to understand. I have not changed the Layout function in the ChartDoc.cs file. I'm adding all the nodes programatically and have made some changes to InsertNodeBeforeNode() and MakeLink(), but there isnt any positioning code in those functions that i've seen. My default Point is 0,0 for adding a node (i tried changing it but it had no effect that i noticed).
John

Sorry for the delay… just getting back from the holidays.



I think I understand now… as you add nodes, the two branches under the Get Language flip back and forth?

Only if one is “taller” than the other. If i keep adding single nodes or stacks of the same size they add in the “correct” left to right order.

In my photos if i added a 3rd branch of 1 item it would appear to the right of the node labeled "first item" if it was 3 items it would appear to the left of the stuff labeled "second branch".
To be honest i havent tried adding another branch of 2 items so i dont know where it would appear. I would assume between "first item" and the "Second branch" stuff in my pictures.
I hope i'm explaining this clearly, creating a sample project would be a pain.
edit
I may have forgotten to mention that i add everything to the document in the code behind. While i add the nodes one at a time, i usually only see them appear in batches. I have set it to add one node at a time before, which is how i was able to notice that things added correctly until one branch had more nodes than another.
/edit
Hope you had a nice holiday.
John

Do you see similar behavior in Flowgrammer?

unfortunatly no, i havent made any changes to the layout code except to remove it from a transaction (i’m not using undo/redo) and some formatting(added whitespace). I just went through it and the layout code matches yours exactly. i removed the label code from MakeLink, other than that its the same.

The only other function i've changed in ChartDoc is InsertNodeBeforeNode. I use the same ports on the different nodes, and since they're being added in the correct order i dont see how it could be a linking or insertion issue. I did set most of the allow's off so that the view is just a display piece and the user cant interact with it.
I'm stepping through the code, but i havent and still dont see anything that would make them move, everything seems to be bieng set correctly. I realize the problem is most likely is in my modifications or my code some place, but i have no idea what could cause this behavior if it isnt something wierd in the layout code or settings.
here is the html for the view control:
<cv:ChartView ID="MyView" runat="Server" Width="600px" Height="500px" Visible="false" BorderWidth="0" ScriptFile="../JS/GoWeb.js" NoPost="True" ImagePage="GoWebImage.axd" BorderStyle="None" BorderColor="Transparent"AllowLink="False" AllowCopy="False" AllowMove="False" AllowResize="False" AllowSelect="false"></cv:ChartView>

I’ve gone through and set labels on the links to verifty the links are what i think they are. the First item gets the first link and the next item added is the last link(looking at the end nodes top port sourcelinks property). Does the order of the links in the source or destination links arrays have anything to do with the layout procedure? If not what does it look at, since i dont specify any positions?

Sorry for the delay, the new year has been busy for us.



First, layered-digraph layout explicitly does not guarantee the ordering of any nodes within a layer.



In fact, it’s supposed to re-order in order to reduce crossings.



And yes, the order of the links going into the algorithm can change the results.



I think I can provide some more help here, but I need to go do some research.

I dont know if it helps, but i do not have any crossings in my document. i have a single bottom port linking to 2 top ports that arrange left to right. I’ve also manage to put labels on the links indicating which is First and Last using the supplied properties, and its moving my Last links to the left of my First links (which i would assume would be the opposite order) I’ve checked both the links coming into the branches and the ones leading to the common End node. and they are all set correctly.

To be clear i use the node.BottomPort.DestinationLinks.First and .Last properties and the end.TopPort.SourceLinks.First and .Last properties and put the lables on them to see where they were. (the names of the nodes have been changed to make it more readable here)
Thanks for your help.

OK, the reason this works in flowgrammer without re-ordering columns of nodes as you add things is this: the “if” node in flowgrammer explicitly has links exiting on the left and right. You’ve changed that so the “Get Language” branches all come out the bottom, effectively telling the Layout that “all these columns are interchangeable”. Does your “Get Language” operation have more than 2 or 3 possible exit paths?



the graph on the left gets laid out how I set it up. The (same) one on the right re-orders columns (all true as long as there are no cross-overs, I believe).







and you probably want to specify



layout.LayeringOption = GoLayoutLayeredDigraphLayering.LongestPathSource



this will put the nodes at the top of the columns instead of the bottom (on paths with fewer nodes).

No, i use the same node for all of my "if"s, and to simpify the logic of trying to balance the nodes out of the left and right node(since there is no real difference to me) i made them all come out of the bottom and let layout branch them. All of my linking logic is based on every link coming from the BottomPort and going into the TopPort on the next node.

I wont have any crossovers, what i'm doing isnt that complicated graphically.
Basically i need to add a new port for each branch i want in order left to right and everything will stay in the order the ports were added, correct?
Thanks for the layoutOption code, i'll try it and see if it helps.

Basically i need to add a new port for each branch i want in order left to right and everything will stay in the order the ports were added, correct?



yes.

Sweet, now that I understand whats going on, i can fix it or at least explain whats happening to the boss and go from there.

I'm surprised that there isnt an option to make link order matter when coming from the same port, you guys usually have options for everything and then some.
Again, thanks for all your help.
John