SpecifiedLayout in Prefuse does not work

200 Views Asked by At

I have a problem using the SpecifiedLayout in Prefuse. I want to set some nodes in positions that are already predefined. I have tried using the AxisLayout. The nodes are set into the right position, but then I can´t really use the options of DragControl or ZoomControl. So I have tried using the SpecifiedLayout. The problem here is that all nodes are set into the same position and not into the positions I specified in the beginning. Hope somebody can help me with this problem.

Here is the code:

private static Visualization vis;
graph = new Graph();

graph.addColumn("positionx", Integer.class);
graph.addColumn("positiony", Integer.class);

Then I add the predefined positions to "positionx" and "positiony". Afterwards:

ActionList layout = new ActionList(ActionList.INFINITY);

SpecifiedLayout l = new SpecifiedLayout("graph.nodes","positionx","positiony");
layout.add(l);
layout.add(new RepaintAction());
vis.putAction("layout", layout);

As I said, if I use the AxisLayout instead of the SpecifiedLayout:

layout.add(new AxisLayout("graph.nodes","positionx",Constants.X_AXIS));
layout.add(new AxisLayout("graph.nodes","positiony",Constants.Y_AXIS));

the nodes are set to the right position, but dragging and zooming is not possible.

I would really appreciate any help.

Thx

2

There are 2 best solutions below

0
On

What do you mean when you say dragging and zooming are not possible with AxisLayout? As long as you add a DragControl and a ZoomControl dragging and zooming should work.

For Example:

display.addControlListener(new DragControl());
display.addControlListener(new ZoomControl());

Does that work for you?

0
On

I've got to make it work (positioning the nodes) after running:

vis.run("layout");

after I've inserted a new node to the graph.

To get the fields updated, you have to set the fields once the items are released.

this.addControlListener(new DragControl() {
    @Override
    public void itemReleased(VisualItem item, MouseEvent e) {
        super.itemReleased(item, e);

        item.set("positionX", item.getX());
        item.set("positionY", item.getY());
    }
});