Gephi API Example

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

+4
source share
2 answers

Gephi updated his docs quite a bit and released a beginner's tutorial:

+4
source

It depends on how you want to display your chart. Perhaps you are trying to import a graphic file and export it in another format, for example 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 should contain information about the positions of the node, otherwise all nodes will be accidentally placed in the visualization area.

To change the rendering properties, you must change some properties of the PreviewModel, for example:

 PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class); PreviewModel model = previewController.getModel(); model.getProperties().putValue(PreviewProperty.SHOW_NODE_LABELS, Boolean.TRUE); 
+4
source

Source: https://habr.com/ru/post/1343996/


All Articles