Reputation: 48218
Help! I'm looking to create a Java application that generates a graph in any one of these formats:
I need to be able to open the file in the graph editor "yEd".
So far, I have found these solutions:
JGraphT Code I Used:
UndirectedGraph<String, DefaultEdge> g = new SimpleGraph<String, DefaultEdge>(DefaultEdge.class);
String v1 = "v1";
String v2 = "v2";
String v3 = "v3";
String v4 = "v4";
// add the vertices
g.addVertex(v1);
g.addVertex(v2);
g.addVertex(v3);
g.addVertex(v4);
// add edges to create a circuit
g.addEdge(v1, v2);
g.addEdge(v2, v3);
g.addEdge(v3, v4);
g.addEdge(v4, v1);
FileWriter w;
try {
GmlExporter<String, DefaultEdge> exporter =
new GmlExporter<String, DefaultEdge>();
w = new FileWriter("test.graphml");
exporter.export(w, g);
} catch (IOException e) {
e.printStackTrace();
}
Any ideas? Thanks!
Upvotes: 8
Views: 9031
Reputation: 133
I created a little Tutorial/Github Repo and sample code on how to work with the classes of JgraphT to export to GraphML and GML and how the results could look like in yED.
As already mentioned in another answer, if you don't want to do much configuration yourself, GML-Writer-for-yED might be handy.
Upvotes: 0
Reputation: 213
I also wanted to export JgraphT graphs for yED but was not happy with the results. Therefore, I created an extended GMLWriter supporting yED's specific GML format (groups, colours, different edges,...).
Upvotes: 3
Reputation: 350
I´m using de Prefuse library and you can generate a GraphML file from a Graph object with de class GraphMLWriter.
Upvotes: 1
Reputation: 91
It might be late to answer, but for solution number two: Right after you import the graph into yEd, just click "Layout" and select one. yed will not choose one for you as default, that's why it seemed to be linear.
Upvotes: 8
Reputation: 6114
Just replace every occurrence of GmlExporter
with GraphMLExporter
in your code. That should work.
Upvotes: 2
Reputation: 526
I don't know if this fits your use case, but I use neo4j for creating a graph and then use the neo4j-shell-tools to export the graph as graphml. Perhaps this will work for you.
Upvotes: 2