I have created a directed Graph (see below). I want to get Node Coordinates from Typ: String.
Graph<String, Edges> graph ;
How can I do this?
The Graph
instance is the data model. Its job is to store the connections between its elements; it doesn't store coordinates, and neither do the vertex or edge objects.
To get coordinates for the vertices, you need to create a Layout
instance for the Graph
instance; once the Layout has generated coordinates for the vertices, you can get the coordinates from the Layout.
Some Layout implementations calculate positions in a single pass (e.g., CircleLayout
); others, in particular the force-directed layouts, require a number of updates (calls to step()
) in order to converge on a set of coordinates that you may find acceptable.
Usually Layout
positions are updated for you by the visualization infrastructure, but you can do it yourself if you like.
You may want to look at the sample code in the JUNG distribution.