tomnelson / jungrapht-visualization

visualization and sample code from Java Universal Network Graph ported to use JGraphT models and algorithms
Other
47 stars 7 forks source link

Hi, can this library be used just to get layout coordinates given a dependency graph, which I want to use to layout in a different front end setup? #22

Closed shivam529 closed 3 years ago

tomnelson commented 3 years ago

You can use the code in the jungrapht-layout jar to apply layout algorithms, then retrieve the Points from the LayoutModel.

tomnelson commented 3 years ago

Here is an example:

    Graph<String, Integer> graph =     // make your graph

    TidierTreeLayoutAlgorithm<String, Integer> layoutAlgorithm =
            TidierTreeLayoutAlgorithm.<String, Integer>edgeAwareBuilder().expandLayout(false).build();
    LayoutModel<String> layoutModel = LayoutModel.<String>builder().size(100, 100).graph(graph).build();
    layoutAlgorithm.visit(layoutModel);

    System.out.println("points are "+layoutModel.getLocations());

If you need the edge articulations (where they bend) for a layout like Sugiyama, you can get the articulation points for each edge using the layout's edgeArticulationFunction

If you choose a layout algorithm that is threaded, you will not get your layout points immediately. Either make it not-threaded or wait for it to finish.