How to set Vertex coordinates in Java JUNG? - java

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.

Related

Scatter plot with Jzy3d

I am using Jsy3d to draw a 3d scatter plot in Java. However, I noticed that the drawing order of the points seems to be based on the order of the given List of Points, not on the distance to the camera. Is there a way to fix this?
You are right, rendering is based on point declaration. Why would you change this?
To change the scatter rendering, simply override Scatter.draw(...)
You may use Camera.getDistance(coord) to get the distance to Camera. This method is already used by BarycenterOrderingStrategy in Graph to order the drawables (but this won't work for your scatter as it is a primitive Drawable).

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 find if two vertices are connected with Jung Framework?

I want to know how to check if two vertices are connected in a graph using Jung Framework.
Thanks.
If the graph is undirected (you haven't specified) or if you don't care about edge direction, use WeakComponentClusterer to split the graph into its (weakly) connected components, and then check to see if the vertices are in the same component. (BicomponentClusterer is not correct for this case if I understood your question correctly.)

Java - Drawing a dynamic shape outline

I wish to create a dynamic outline to a Shape (AWT) by adding objects (with draw functions) to appropriate positions on screen along the shape's perimeter. I want a roughly even distance between each object. (An alternative approach to the same affect will be fine.)
How might I acquire the locations for these objects? I know shapes have a path iterator, but I have no idea how to use it.
You might look at a library such as the one described in A Shape Diagram Editor.
If you want to experiment, GraphPanel is a simple object drawing program that features moveable, resizable, colored nodes connected by edges. If the nodes were a little smaller, they'd be moveable points on a Shape that can be iterated as shown here for Polygon.
Addendum: I want a roughly even distance between each object.
The class Node exposes a number of static methods that operate on a List<Node> such as selected. Existing implementations serve, for example, to translate or resize multiple selections as a unit. Functions for Align and Distribute could be implemented similarly. I'd look at LayoutManger as an example for the latter.
Use FlatteningPathIterator to get points for Shape's path.
Also you can use BasicStroke's method
public Shape createStrokedShape(Shape s)
to get Shape's outline with desire width.

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.

Categories

Resources