Prefuse graph manually set force parameters

半腔热情 提交于 2019-12-02 00:50:13
trashgod

One approach might be to add a JForcePanel, which is a

Swing component for configuring the parameters of the Force functions in a given ForceSimulator. Useful for exploring different parameterizations when crafting a visualization.

This might help you to find the optimal parameters to use in your implementation of getForceSimulator().

ForceSimulator fsim = ((ForceDirectedLayout) layout.get(0)).getForceSimulator();
JForcePanel fpanel = new JForcePanel(fsim);
frame.add(fpanel, BorderLayout.SOUTH);

Among the demos included in the distribution, prefuse.demos.GraphView is a complete example. Empirically, it seems as though some parameters have more or less effect depending on the chosen data set.

Addendum: Looking closer, I see that your approach leaves the internal state of fdl unchanged. Instead, create a new ForceSimulator and use it in the layout and force panel; the example below changes the defaultLength of a SpringForce from DEFAULT_SPRING_LENGTH to 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);

Alternatively, update the SpringForce directly, as shown here.

ForceDirectedLayout fdl = new ForceDirectedLayout("graph");
ForceSimulator fs = fdl.getForceSimulator();
Force[] forces = fs.getForces();
SpringForce sf = (SpringForce) forces[2];
sf.setParameter(SPRING_LENGTH, 42);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!