Search code examples
javajung

how to display a DirectedSparseMultigraph as a tree


I have a DirectedSparseMultigraph graph with four kind of relations. One of these is organizational links, so I would like to filter my graph and display the network as a tree. I filter my network like:

Predicate<Link> advLinks = new Predicate<Link>() {
     @Override
     public boolean evaluate(Link e) {
          return e instanceof Organizational;
     }
};
EdgePredicateFilter<Vertex, Link> advPredicateFilter = new EdgePredicateFilter<>(advLinks);
DirectedSparseMultigraph filtered = advPredicateFilter.transform(graph);
graphLayout = new KKLayout<>(filtered); 
((KKLayout<Vertex, Link>) graphLayout).setMaxIterations(1000);
visualizationModel.setGraphLayout(graphLayout);
vv.repaint();

So far I can only represent this filtered network using a normal layout, but the organizational nature of these data is lost... How can I convert my DirectedSparseMultigraph to a DelegateTree?


Solution

  • http://jung.sourceforge.net/site/jung-samples/xref/edu/uci/ics/jung/samples/MinimumSpanningTreeDemo.html

    tl;dr Build a spanning tree for your original graph, lay that out, and then use the vertex positions from that layout to lay out your original graph.