2

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?

Michael Schubert
  • 2,726
  • 4
  • 27
  • 49

1 Answers1

2

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));
Kamil
  • 36
  • 1
  • Thanks, that solved it. Haven't thought of it because rendering does not need a specified size, yet the transformer seems to do. – Michael Schubert Nov 10 '11 at 12:31
  • 1
    IIRC, rendering doesn't need you to specify a size because the rendering code will provide one if you don't. The positions can't be initialized until the layout knows the size of the canvas that it has to work with. – Joshua O'Madadhain Nov 10 '11 at 17:39