Reputation: 127
I have an adjacency list representation of a graph in a text file. E.g.
0 -> 1, 2
1 ->
2 -> 1
3 -> 1
I want to create an image for this graph from the input text file, the graph should look like this:
Is there any software available in Java or any other language that can help me achieve this?
Upvotes: 0
Views: 1011
Reputation: 48278
There is a good lib for that, the Universal Network/Graph Framework
here an Example:
public static void main(String[] args) {
DirectedSparseGraph<String, String> g = new DirectedSparseGraph<>();
g.addVertex("0");
g.addVertex("1");
g.addVertex("2");
g.addVertex("3");
g.addEdge("Edge1", "0", "1");
g.addEdge("Edge2", "0", "2");
g.addEdge("Edge3", "2", "1");
g.addEdge("Edge4", "3", "1");
VisualizationImageServer<String, String> vv = new VisualizationImageServer<>(new CircleLayout<>(g),
new Dimension(600, 400));
Transformer<String, String> transformer = new Transformer<String, String>() {
@Override
public String transform(String arg0) {
return arg0;
}
};
vv.getRenderContext().setVertexLabelTransformer(transformer);
JFrame frame = new JFrame("My Graph");
frame.setLocationRelativeTo(null);
frame.getContentPane().add(vv);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
Upvotes: 1