I'm using Gephi to create a graphmodel and then export that into a .graphml file. However when I create the .graphml file the colour attribute is not maintained.
The following is how I create a gephi graphmodel from my GraphClass (comprised of edges of type E, and nodes of type V) and export it to a .graphml file. In this case I create a random K-tree
public void testCreateGraph() throws Exception {
KTree K1 = new KTree(4);
for (int i = 0; i < 95; i++) {
K1.addRandomVertex();
}
GraphMLCreator<KVertex,KEdge<KVertex>> creator = new GraphMLCreator();
creator.create(K1);
creator.sendToDB();
}
public void create(GraphClass<V,E> G){
graph = graphModel.getUndirectedGraph();
this.addNodes(G.getVertices());
this.addEdges(G.getEdges());
}
private void addEdges(Collection<E> edges){
for (E e: edges){
Node n0 = graph.getNode(e.getEndPoints().getFirst().getLabel());
Node n1 = graph.getNode(e.getEndPoints().getSecond().getLabel());
org.gephi.graph.api.Edge e1 = graphModel.factory().newEdge(n0, n1, 1f, false);
graph.addEdge(e1);
}
}
private void addNodes(Collection<V> nodes){
for (V v:nodes){
Node n0 = graphModel.factory().newNode(v.getLabel());
n0.getNodeData().setLabel(v.getLabel());
n0.getNodeData().setColor(255,0,0);
graph.addNode(n0);
}
}
public void createGraphML(){
//Export full graph
ExportController ec = Lookup.getDefault().lookup(ExportController.class);
try {
ec.exportFile(new File("io_gexf.gexf"));
} catch (IOException ex) {
ex.printStackTrace();
return;
}
//Export only visible graph
GraphExporter exporter = (GraphExporter) ec.getExporter("gexf"); //Get GEXF exporter
exporter.setExportVisible(true); //Only exports the visible (filtered) graph
exporter.setWorkspace(workspace);
try {
ec.exportFile(new File("io_gexf.gexf"), exporter);
} catch (IOException ex) {
ex.printStackTrace();
return;
}
//Export to Writer
Exporter exporterGraphML = ec.getExporter("graphml"); //Get GraphML exporter
exporterGraphML.setWorkspace(workspace);
StringWriter stringWriter = new StringWriter();
ec.exportWriter(stringWriter, (CharacterExporter) exporterGraphML);
FileWriter fw = null;
try {
fw = new FileWriter("my-file.graphml");
fw.write(stringWriter.toString());
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
I want to set the colour of the nodes to red but in yED It just shows them as the default yellow
A Node from the GraphML looks as follows:
<node id="V0">
<data key="label">V0</data>
<data key="size">1.0</data>
<data key="r">65025</data>
<data key="g">0</data>
<data key="b">0</data>
<data key="x">418.6446</data>
<data key="y">-191.08676</data>
</node>
Is there some way in Gephi to directly change the value of a specific data tag? I believe my problem is the format of the graphml data tag is incorrect and not recognized by yED, and that this incorrect format may have to do with how it the file is written.