Gephi API example
Asked Answered
L

2

6

Can somebody give me an example of how to display programmatically a graph with Gephi from a .graphml file? Thanks.

Loyce answered 16/3, 2011 at 19:46 Comment(0)
O
5

Gephi has upgraded their docs quite a bit and released a tutorial for beginners:

Overfeed answered 9/5, 2011 at 16:55 Comment(2)
Gephi can be integrate with web applcation, to generate dynamic graph?Gratianna
Gephi is primarily designed for individual desktop use. I'd recommend looking into cytoscape.js or d3's force directed graph example.Overfeed
K
5

It depends on how you want to display your graph. Probably you are trying to import a graphml file and export it in some other format, like png or pdf, using Gephi.

Your Java class should do something like this:

File graphmlFile = new File("graph.graphml");

//Init a project - and therefore a workspace
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
Workspace workspace = pc.getCurrentWorkspace();

// get import controller
ImportController importController = Lookup.getDefault().lookup(ImportController.class);

//Import file
Container container = importController.importFile(graphmlFile);

//Append imported data to GraphAPI
importController.process(container, new DefaultProcessor(), workspace);

//Export graph to PDF
ExportController ec = Lookup.getDefault().lookup(ExportController.class);
ec.exportFile(new File("graph.pdf"));

Of course, your graph.graphml file must include information about node positions, otherwise all nodes will be randomly placed in the visualization area.

To change visualization properties, you must change some PreviewModel properties, e.g:

PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
PreviewModel model = previewController.getModel();
model.getProperties().putValue(PreviewProperty.SHOW_NODE_LABELS, Boolean.TRUE);
Knesset answered 12/10, 2012 at 14:8 Comment(1)
"Programmatically" means you have to write it in Java, compile and run, using a Java IDE like Netbeans. It is not supposed to be written in Gephi, but just to use Gephi libraries (like the toolkit: gephi.github.io/toolkit).Bolte

© 2022 - 2024 — McMap. All rights reserved.