Using API to layout with ForceAtlas2

Once it's running
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
rlb.graph
Posts:2
Joined:23 Jun 2016 21:44
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
Using API to layout with ForceAtlas2

Post by rlb.graph » 23 Jun 2016 22:17

New user here - please advise if there is a better place for this question.

I'm trying to get the Gephi API to replicate what I can get in the Gephi viewer (screenshot below).
Image

I have adapted code from the API samples that uses ForceAtlasLayout and can get the code to run using ForceAtlas2 instead. However the results I get are very different visually (just a blob of overlapping nodes).

I could find some of the options in the viewer in the ForceAtlas2 java class (e.g., LinLog), but not all of them. I dug in the source code and found some dynamic properties that seem to match up, but the visual results I'm getting still suck.

I've pasted my code below including some commented out code from the API samples. One note about the data, when I parsed the json and created Gephi nodes I did not store the "group" property anywhere - perhaps that is part of the issue, but I'm assuming that is just used to specify color and size of circle which I don't care about yet.

Can anyone help explain how to make this code work? I can upload the json parsing code as well, but thought I'd just post the Gephi layout code first.



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

//parse json at https://bost.ocks.org/mike/miserables/miserables.json
//and create DirectedGraph (code not shown)
DirectedGraph graph = this.parseMiserablesData();
GraphModel graphModel = graph.getGraphModel();

//Layout for 1 minute
AutoLayout autoLayout = new AutoLayout(1, TimeUnit.MINUTES);
// AutoLayout autoLayout = new AutoLayout(3, TimeUnit.SECONDS);

autoLayout.setGraphModel(graphModel);
YifanHuLayout firstLayout = new YifanHuLayout(null, new StepDisplacement(1f));

autoLayout.addLayout(firstLayout, 0.5f);


//ForceAtlasLayout - code copied from API sample
// ForceAtlasLayout secondLayout = new ForceAtlasLayout(null);
// AutoLayout.DynamicProperty adjustBySizeProperty = AutoLayout.createDynamicProperty(
// "forceAtlas.adjustSizes.name",
// Boolean.TRUE,
// 0.1f);//True after 10% of layout time
// AutoLayout.DynamicProperty repulsionProperty = AutoLayout.createDynamicProperty(
// "forceAtlas.repulsionStrength.name",
// new Double(5500.0), //500
// 0f);//500 for the complete period
// autoLayout.addLayout(secondLayout, 0.5f, new AutoLayout.DynamicProperty[]{
// adjustBySizeProperty,
// repulsionProperty
// });

//ForceAtlas2 - code adapted from ForceAtlasLayout above
ForceAtlas2 secondLayout = new ForceAtlas2(new ForceAtlas2Builder());
secondLayout.setLinLogMode(true);
//secondLayout.setAdjustSizes(true);//Prevent Overlap
secondLayout.setScalingRatio(30d);
secondLayout.setGravity(10d);
secondLayout.setEdgeWeightInfluence(0.2);
AutoLayout.DynamicProperty adjustBySizeProperty = AutoLayout.createDynamicProperty(
"ForceAtlas2.adjustSizes.name",
Boolean.TRUE,
0f);//True for the complete period
AutoLayout.DynamicProperty distrAttraction = AutoLayout.createDynamicProperty(
"ForceAtlas2.distributedAttraction.name",
Boolean.TRUE,
0f);//True for the complete period
autoLayout.addLayout(secondLayout, 0.5f, new AutoLayout.DynamicProperty[]{
adjustBySizeProperty,
distrAttraction
});


autoLayout.execute();

return graph;


Thanks very much.

Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable