Michael Schubert
Michael Schubert

Reputation: 2796

How to use JUNG layout transformations correctly?

I have got some issues using the DAGLayout algorithm of JUNG and subsequently reading out the layout coordinates into my own data structure again.

I have got a Network class with lists of Nodes and Edges. To convert this to a JUNG data structure, I create a DirectedSparseMultigraph object and add the edges. e.getSrc() and e.getDest() return Node objects.

DirectedSparseMultigraph<Node, Edge> graph;
for (Edge e : net.getEdges()) {
    graph.addEdge(e, e.getSrc(), e.getDest());
}

Then, I apply the layout algorithm.

Layout<Node, Point2D> layout;
layout = new DAGLayout(graph);

After that, I use to layout to get the vertex coordinates.

for (Node node : net.getNodes()) {
    Point2D coord = layout.transform(node);
    node.setPos((float)coord.getX(), (float)coord.getY());
}

But the Node objects always have (0,0) as (x,y).

Why does this not work this way, and how do I fix it?

Upvotes: 2

Views: 1575

Answers (1)

Kamil
Kamil

Reputation: 36

I'm not too familiar with JUNG, but I think you have to first specify size of the layout, for example:

layout.setSize(new Dimension(800,600));

Upvotes: 2

Related Questions