Reputation: 2796
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 Node
s and Edge
s. 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
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