jungjung2

JUNG layout for left-to-right placement of nodes


Is there an optimal layout in JUNG for left-to-right placement of nodes in the graph? I'm looking for something that would model a data lineage and need to represent this somewhat linearly (left to right).


Solution

  • If your graph is a tree, then you can use the TreeLayout and do some post-processing to rotate it to have the root on the left instead of the top (see the L2RTreeLayoutDemo for an example of how to do this).

    If your graph is only sort of tree-shaped, then you may want to extract a tree from your graph first (see MinimumSpanningTreeDemo for one way to do this automatically) and then follow the procedure above.

    If neither of those works for you (for example, this won't work if your graph has multiple "roots"), then you will probably need to create your own layout, perhaps based on TreeLayout.