The preprocessing graph manually sets the force parameters

Like here , my Prefuse graph is too tight to see. So I tried the approach suggested by @bcr in the accepted answer. However, this doesn't work for me. This is what I tried:

I got the default settings. Then I changed the second parameter NBodyForce

from ForceSimulator

(called Distance

) and the second parameter SpringForce

(called DefaultSpringLength

) and fed them along with other defaults - to my new one ForceSimulator

. But nothing in the output has changed. What am I wrong?

This is my code:

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");
}

      

+2


source to share


1 answer


One approach might be to add JForcePanel

, which is

Swing component for setting parameters of functions Force

in a given ForceSimulator

. Useful for exploring various options when creating a visualization.

This can help you find the optimal parameters to use in your implementation getForceSimulator()

.

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

      

Among those demos

included in the distribution prefuse.demos.GraphView

is a complete example. Empirically, some parameters seem to have more or less effect depending on the dataset selected.



Adding . Coming closer, I can see that your approach leaves the internal state fdl

unchanged. Instead, create a new one ForceSimulator

and use it in the layout and strength panel; the example below changes defaultLength

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 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);

      

image

+2


source







All Articles