喜欢here ,我的 Prefuse 图太密集,看不到任何东西。所以我尝试了@bcr 在接受的答案中建议的方法。但是,它对我不起作用。这是我尝试过的:
我检索了默认设置。然后我将 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
,它是一个
Swing component for configuring the parameters of the
Force
functions in a givenForceSimulator
. Useful for exploring different parameterizations when crafting a visualization.
这可能会帮助您找到在 getForceSimulator()
实现中使用的最佳参数。
ForceSimulator fsim = ((ForceDirectedLayout) layout.get(0)).getForceSimulator();
JForcePanel fpanel = new JForcePanel(fsim);
frame.add(fpanel, BorderLayout.SOUTH);
在发行版中包含的演示
中,prefuse.demos.GraphView
是一个完整的示例。根据经验,似乎某些参数的影响或多或少取决于所选的数据集。
附录:仔细观察,我发现您的方法使 fdl
的内部状态保持不变。相反,创建一个新的 ForceSimulator
并在布局和力面板中使用它;下面的示例将 SpringForce
的 defaultLength
从 DEFAULT_SPRING_LENGTH
更改为 42
。
ForceDirectedLayout fdl = new ForceDirectedLayout("graph");
ForceSimulator fs = new ForceSimulator();
fs.addForce(new NBodyForce());
fs.addForce(new DragForce());
fs.addForce(new SpringForce(DEFAULT_SPRING_COEFF, 42));
fdl.setForceSimulator(fs);
或者,直接更新SpringForce
,如图here .
ForceDirectedLayout fdl = new ForceDirectedLayout("graph");
ForceSimulator fs = fdl.getForceSimulator();
Force[] forces = fs.getForces();
SpringForce sf = (SpringForce) forces[2];
sf.setParameter(SPRING_LENGTH, 42);
关于java - Prefuse图表手动设置力参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30441734/