gpt4 book ai didi

java - Prefuse graph手动设置force参数

转载 作者:行者123 更新时间:2023-11-30 08:51:42 26 4
gpt4 key购买 nike

here ,我的 Prefuse 图太密集了,看不到任何东西。所以我尝试了@bcr 在接受的答案中建议的方法。但是,它对我不起作用。这是我试过的:

我检索了默认设置。然后我更改了 ForceSimulatorNBodyForce 的第二个参数(称为 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 given ForceSimulator. 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);

在发行版中包含的demo 中,prefuse.demos.GraphView 是一个完整的示例。根据经验,似乎某些参数或多或少会根据所选数据集产生影响。

附录:仔细观察,我发现您的方法没有改变fdl 的内部状态。相反,创建一个新的 ForceSimulator 并在布局和力面板中使用它;下面的示例将 SpringForcedefaultLengthDEFAULT_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);

image

关于java - Prefuse graph手动设置force参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30441734/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com