就像这里一样,我的 Prefuse 图太密集了,看不到任何东西。所以我尝试了@bcr 在接受的答案中建议的方法。但是,它对我不起作用。这是我尝试过的:
我检索了默认设置。然后我更改了NBodyForce
from ForceSimulator
(called Distance
) 的第二个参数和SpringForce
(called DefaultSpringLength
) 的第二个参数,并将它们连同其他默认值一起输入到我的 newForceSimulator
中。但是输出中没有任何变化。我怎么了?
这是我的代码:
private static void visualiseGraph(Graph graph) {
Visualization vis = new Visualization();
vis.add("graph", graph);
LabelRenderer r = new LabelRenderer("someLabel");
r.setRoundedCorner(8, 8);
vis.setRendererFactory(new DefaultRendererFactory(r));
ColorAction fill = new ColorAction("graph.nodes",
VisualItem.FILLCOLOR, ColorLib.rgb(190,190,255));
ColorAction text = new ColorAction("graph.nodes",
VisualItem.TEXTCOLOR, ColorLib.gray(0));
ColorAction edges = new ColorAction("graph.edges",
VisualItem.STROKECOLOR, ColorLib.rgb(255,180,180));
ActionList color = new ActionList();
color.add(fill);
color.add(text);
color.add(edges);
ActionList layout = new ActionList(Activity.INFINITY);
Force[] originalForces = new ForceDirectedLayout("").getForceSimulator().getForces();
ForceDirectedLayout fdl = new ForceDirectedLayout("graph"){
@Override
public ForceSimulator getForceSimulator() {
ForceSimulator fs = new ForceSimulator();
fs.addForce(new NBodyForce(originalForces[0].getParameter(0), 100, originalForces[0].getParameter(2)));
fs.addForce(originalForces[1]);
fs.addForce(new SpringForce(originalForces[2].getParameter(0), 100));
return fs;
}
};
layout.add(fdl);
layout.add(new RepaintAction());
vis.putAction("color", color);
vis.putAction("layout", layout);
Display display = new Display(vis) {
@Override
public Dimension getPreferredSize() {
return new Dimension(W, H);
}
};
display.pan(W / 2, H / 2);
display.addControlListener(new DragControl()); // drag items around
display.addControlListener(new PanControl()); // pan with background left-drag
display.addControlListener(new ZoomControl()); // zoom with vertical right-drag
JFrame frame = new JFrame("prefuse example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(display);
frame.pack();
frame.setVisible(true);
vis.run("color");
vis.run("layout");
}