I have some layout behaviour that I want to change.
I have tried a few approaches, but none seem to be working.
We have an application that acts as a workbench for performing a business process.
The process is highly iterative, so we are using a JGO view render a view with each step in the process represented as a node.
The view is more than a chronological sequence of steps - it is more of a decision tree.
So a user may go through the following steps:
1
2
3
and then go back to #2 and create step 4
1
2
3 4
The "chronological" sequencing left to right is important to maintain.
However when I use JGoLayeredDigraphAutoLayout
it seems to switch the position of sub branches at certain times, e.g.
I get the following tree rendered.
1
2 4
3 6 & ;nbs p; 5
Do you know how I can control the switching of #5 and #6?
Well, the layered-digraph autolayout is designed to re-order the nodes
in a layer, in order to try to reduce the number of crossings, so what
I believe you want isn’t a natural behavior. But it is possible
to disable the re-ordering; I can supply details next week.
Well, first, I hope you understand that the layered-digraph autolayout was designed to re-order the nodes at each logical layer so as to try to reduce the number of link crossings. But you can disable that by overriding a couple of methods to be no-ops.
public class TestLDLayout extends JGoLayeredDigraphAutoLayout { public TestLDLayout() {} // ??? or add the constructor you want to use public void reduceCrossings() {} protected boolean adjacentExchangeCrossingReductionBendStraighten(int unfixedLayer, int directionCR, boolean straighten, int directionBS) { return false; } }
Then you just need to specify the order somehow.
One way is to make sure the JGoNetworkLinks are added in the right order, when the JGoNetwork is constructed.
The more general way is to override initializeIndices.
getNetwork().getNodeArray() returns an array of all the JGoNetworkNodes. For each layer, you need to find all of the JGoNetworkNodes whose JGoLayeredDigraphAutoLayoutNodeData.layer are that layer, and then you need to assign each JGoLayeredDigraphAutoLayoutNodeData.index to specifiy the ordering you want. At the end the getIndices() array has to have the count of nodes for each layer.
protected void initializeIndices() { JGoNetworkNode[] nodearray = getNetwork().getNodeArray(); for (int layer = 0; layer <= getMaxLayer(); layer++) { // find all the JGoNetworkNodes on a particular layer ArrayList nodelist = new ArrayList(); for (int ni = 0; ni < nodearray.length; ni++) { JGoNetworkNode pNode = nodearray[ni]; if (nodeData(pNode).layer == layer) nodelist.add(pNode); } JGoNetworkNode[] nodes = (JGoNetworkNode[])nodelist.toArray();
… sort the nodes in the way you want
// assign each node’s index, and update the indices array // to hold the count of nodes in that layer int[] indices = getIndices(); for (int i = 0; i < nodes.length; i++) { // assign each nodeData(pNode).index to a non-negative value // to specify the ordering of pNode in the given layer JGoNetworkNode pNode = (JGoNetworkNode)nodes; nodeData(pNode).index = indices[layer]++; } } }
OK, that seems to have stopped “column” switching.
However, one isde effect is that one of the links follows an indirect route that crosses a node, when in fact it should be routed directly between “parent” and “child” node.
Is there any way I can tidy up the link routing independently of the column switching?