java graph visualization w/ topological layout - java

Is there a graph visualization library which supports laying out the graph in a way such that
the X(or Y) coordinates of nodes are topologically sorted?
Alternatively, I could assign a number to every node, it could lay out the nodes in a way that their Y coordinates respect the ordering of the associated number.
Can JGraph or Jung do that?

JUNG does not provide such a layout but you can define your own layout algorithms.

Related

GraphStream drawing grouped nodes in graph

I already created graph with different color each graph based on some attribute in its node. This is my current graph
Is it possible to place node that has same color closely? How could I implement that?
I am looking for a similar functionality and came across Viewers (http://graphstream-project.org/doc/Tutorials/Graph-Visualisation_1.0/). I disabled the default viewer and mentioned co-ordinates for individual nodes (which works but doesn't look pretty and is additional headache to mention co-ordinates in the code).
However, I haven't figured out if we can still use default viewer and group nodes based on some attributes.
Let me know if you figure out a way to do that.

How to draw a tree in java language

I am trying to parse an XML file in java, after I have to represent it as a tree using Jframe like this
Trees are generally one of the easier linked constructs to lay out like this, because paths generally don't "merge" or "cross".
You can approach it in a roughly tabular way by traversing the tree "left to right": start at the root, and draw its representation at the top left of the area. Then, traverse its "left" branch one level at a time, drawing those nodes' representations on successively lower "rows", in the same "column" as the root. Then, as you move to the "right"-side nodes, draw that node in the next "column" available to the right on the same level. This will produce a ramp-shaped graph of the tree's structure.
You can add some pre-analysis of the number of levels and nodes at each level, which will allow you to "center" the tree into a rough pyramid shape by knowing the maximum number of levels the graph will require and the number of nodes at each level of that graph. But, that requires traversing the entire graph before you start drawing anything.
As for "arranging" a tree's nodes so they fit in the smallest area without arrows crossing or overlapping, that's a problem with a scope far exceeding the average SO answer.
There are lots of good libraries for visualizing graphs.
Here's a pretty extensive list of options: http://s6ai.livejournal.com/33969.html
Us the standard forms to print the image
http://www.java-forums.org/awt-swing/6763-how-display-image.html
Prefuse could probably create something aesthetically similar. Of course, you could go the primitive route and do the graphics manually. For an XML to graph transform, the TreeMLReader API may be of some use, however you might have to convert the XML to the TreeML format with XSLT first.

How to set Vertex coordinates in Java JUNG?

I need to specify position of all graph's vertices.
Is it possible?
Please help.
If what you're saying is that you have existing vertex coordinates and you want to use those to lay out your graph in JUNG, that's what StaticLayout is for.
Classes in edu.uci.ics.jung.algorithms.layout used by edu.uci.ics.jung.visualization:
GraphElementAccessor: Interface for coordinate-based selection of graph components.
Layout: A generalized interface is a mechanism for returning (x,y) coordinates from vertices.
Described here.

How to plot a node in given coordinate using JUNG

I want to virtualize my network simulations and need to plot the nodes in the network. Each node has a pre-defined location and I need to plot the nodes into the correct coordination.
I am using JUNG: http://jung.sourceforge.net/applet/index.html
Any suggestions?
Thanks!
I recently solved this problem by writing my own rendering Layout for JUNG.
As base for my derived layout I used the Circle Layout, which is pretty simple. In there you will see that JUNG does a setLocation(Dimension d) for every Vertex, which is pretty much what you are looking for, I guess. Just take a look at the source of the CircleLayout.
Then you could use a custom Vertex object, which stores the coordinates you want the vertex to have, which is then read by your custom layout.

how can i draw a tree hierarchy using JUNG?

I'm new to JUNG. I tried to draw a graph of a tree using the TreeLayout but the tree never comes out like a real tree. Every time the tree looks different. How can I make the tree look like a normal tree with the root on top & the rest of the nodes descending from it?
You have to Initialize the TreeLayout after adding the Vertexes to the graph, I tried that and it worked for me.
You have to do something like the following: (please note that this is a 1 year old code that i had, you might find it to be a little out dated)
Layout<GraphVertex, GraphEdge> layout; //create a layout
layout = new TreeLayout<GraphVertex, GraphEdge>((Forest<GraphVertex, GraphEdge>) g);
// initialize your layout using the graph you created, which has to be of type forest
vv.setGraphLayout(layout);
// set the layout of the visualization viewer you are using to be the layout you just created (the tree layout)
GraphVertex Is the class which represents a vertex in the graph, GraphEdge represents the edges in your graph.

Categories

Resources