與here一樣,我的Prefuse圖過於密集,無法看到任何東西。所以我在接受的答案中嘗試了@bcr提出的方法。但是,它不適合我。這是我試過的:Prefuse圖手動設置力參數
我檢索了默認設置。然後,我將NBodyForce
的第二個參數從ForceSimulator
(稱爲Distance
)和第二個參數SpringForce
(稱爲DefaultSpringLength
)更改爲我的新ForceSimulator
,並將它們與其他默認值一起輸入。但輸出中沒有任何變化。我錯了什麼?
這是我的代碼:
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");
}
非常感謝你。 JForcePanel非常有用,並且是一個有趣的玩具,同時以您完美運行的方式設置部隊參數。 – anjuta
對於那些可能會遇到同樣問題的人,我做了一個評論:我必須做fs.addForce(新的SpringForce(SpringForce.DEFAULT_SPRING_COEFF,)); NBody和DragForces的構造函數只接受float,而不是double,這是Java中的默認值。 –
anjuta
還有一點評論:你可以使用比JForcePanel建議的值更廣泛的值,並且它們會生效。 – anjuta