I am using the toolkit for building PDF network files from GFEX input files. I would like two things:
1. That the weight will be proportional to the distance. I understand this can be done using the force atlas layout algorithm.
2. I'd like the labels to not overlap.
The question is how to implement this...
Currently I am using the following code for layout:
- Code: Select all
//Run YifanHuLayout for 100 passes - The layout always takes the current visible view
YifanHuLayout layout = new YifanHuLayout(null, new StepDisplacement(1f));
layout.setGraphModel(graphModel);
layout.resetPropertiesValues();
layout.setOptimalDistance(600f);
layout.initAlgo();
for (int i = 0; i < 100 && layout.canAlgo(); i++) {
layout.goAlgo();
}
layout.endAlgo();
ForceAtlas2 fa2Layout = new ForceAtlas2(new ForceAtlas2Builder());
fa2Layout.setGraphModel(graphModel);
fa2Layout.resetPropertiesValues();
fa2Layout.setEdgeWeightInfluence(1.0);
fa2Layout.setGravity(1.0);
fa2Layout.setScalingRatio(2.0);
fa2Layout.setBarnesHutTheta(1.2);
fa2Layout.setJitterTolerance(0.1);
for (int i = 0; i < 100 && fa2Layout.canAlgo(); i++)
fa2Layout.goAlgo();
Node[] nodes = graphModel.getGraph().getNodes().toArray();
System.out.println(nodes.length);
for (int i = 0; i < nodes.length; i++)
{
//Get the TextDataImpl object
TextDataImpl td=(TextDataImpl) nodes[i].getNodeData().getTextData();
String labelText=nodes[i].getNodeData().getLabel();
td.setText(labelText);
//Could perhaps used getFontMetrics here to be more accurate but
// this heuristic seems to work for me:
Rectangle2D bounds=new Rectangle(labelText.length()*100,100);
//Use reflection to set the protected Bounds data to non-zero sizes.
Field protectedLineField = TextDataImpl.class.getDeclaredField("line");
protectedLineField.setAccessible(true);
TextLine line = (TextLine) protectedLineField.get(td);
line.setBounds(bounds);
}
LabelAdjust laLayout = new LabelAdjust(new LabelAdjustBuilder());
laLayout.setGraphModel(graphModel);
laLayout.resetPropertiesValues();
laLayout.setAdjustBySize(true);
laLayout.initAlgo();
for (int i = 0; i < 50000 && laLayout.canAlgo(); i++)
laLayout.goAlgo();
laLayout.endAlgo();
//
