How to plot a node in given coordinate using JUNG - java

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.

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.

java graph visualization w/ topological layout

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.

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.

Algorithm for drawing a graph structure?

I have a digraph graph G=(V,E) that I would like to redraw because it is currently very messy. This is a flow chart that is being visualized and since |V|>1000 and each v in V has more than 1 outgoing edge, it is very hard to trace by eye. For instance; a node on the lower left corner is connected by an edge to a node on the upper right corner. It would be better, for example, if these two nodes were placed next to each other. There are too many edges and it is a pain to trace each of them.
I have access to and can change the (x,y) coordinates of all the vertices. I would like to redraw G by maintaining it's current structure, in a way that is more human-friendly. I thought that minimizing the number of intersecting edges may be something to start with.
Is there an algorithm that can help me redraw this graph?
My question is, how do I assign (x,y) coordinates to each v in V such that it is organized better and easier to trace and read? How do I express these requirements formally? Should I go with a heuristic, if this is NP? Here is an example for a somewhat organized graph and this is something messy (although much smaller than what I'm dealing with).
Any help will be greatly appreciated. Thanks.
EDIT: I'm still looking for a to-the-point answer. I've researched into planar straight-line and orthogonal drawing methods but what I've got is lengthy research papers. What I'm seeking is an implementation, pseudo-code or at least something to get me started.
EDIT 2: I'm not trying to display the graph. The input to the algorithm shall be the graph G (composed of V and E) and the output shall be {(xi, yi) for each vi in V}
You want to look at graphviz.org; this is a difficult problem on which there has been a lot of research, reimplementing the wheel is not the right way to go.
Probably you'll have to get the java to write out a datafile which a tool like 'dot' can read and use for the graph layout.
That messy one seems to be drawn using spline, try planar straight line algorithm instead. Indeed this is a very difficult problem and I always use GraphViz as my backend graph drawing tools, you can generate that graph you want with -Gsplines=line option.

How to make a customizable graph

I'm looking to use the java2d API to make a graph in which users can manipulate certain features using their mouse - such as the scale used for an axis or move around the different points plotted on the graph.
So far all I have found is the drawX methods on a Graphics2D object, however there does not seem to be an easy way to capture a user clicking on one of these and moving it so that I can redraw the graph.
Can anyone suggest the best/easiest way to implement this? Just looking for a point in the right direction.
Not reinventing the wheel is always the best way, there are plenty of excellent libraries you can use: http://www.jfree.org/jfreechart/
If you are looking to implement this yourself, you would listen to mouse events on whatever component you're actually using to display your chart (say a JPanel), and then would have to convert between screen and chart coordinates to figure out what you need to change.

Categories

Resources