tags:

views:

1909

answers:

3

I'm currently using Jung to draw graphs (I really mean graphs not charts!).

The problem: Vertex and Edge Labels are overlapping with the Vertexes and the Edges. This leads into strange looking graphs:

Strange Graph Labeling

the "produces" label is overlapping with the vertex and the "60" edge-label is also overlapping with the vertex.

Are there any possibilities to tell JUNG to prevent these overlappings? I hoped this is already implemented and the only problem is to find the right options!

The Problem is not bound to a specific Layout-Algorithm (this was done using a FRLayout).

Thanks!

+1  A: 

I think this is just how its implemented, the authors of the code probably don't see it as an issue. The JUNG library is open-source so you are welcome to make changes to it as you see fit.

If you don't want to change the code an easy fix to make the labels more readable would be to simply change the color of the labels, so they differ from the edges.

ldog
+2  A: 

(The following answer assumes Jung2; I'm not familiar with pre-Jung2).

One of Jung's strengths is that it is very extensible, and easily extended. Jung allows you to plug in various transformers (simple rendering properties), renderers (more complex rendering), and so forth, to customize the behavior when the default isn't quite right. These are typically installed on the RenderContext (which you can get from your VisualizationViewer).

On the flip side, its drawbacks are its complexity and lack of decent documentation. If you're going to do any moderate to heavy customization, you'll need to dig into the Jung source.

For example, the vertex label rendering can be customized by plugging in a new vertex label renderer (Renderer.VertexLabel interface). For example, you can instantiate BasicVertexLabelRenderer and specifying a different position (north, west, center, etc.). You could put your label at the center, if you are willing to change the shape into something larger than that circle (to do so, install your own vertex shape transformer -- an instance of Transformer). Alternatively, you could create your own custom implementation of this interface which renders a background under the label text.

You could also install your own tweaked version of Renderer.EdgeLabel (see Jung's BasicEdgeLabelRenderer) to customize the positioning of the edge label.

JimN
+1  A: 

by the way, if you do want to change the color, at first it appears to be a major pain. but I recently discovered this little trick:

Transformer labelTransformer = new ChainedTransformer<String,String>(new Transformer[]{
            new ToStringLabeller<String>(),
            new Transformer<String,String>() {
            public String transform(String input) {
                return "<html><font color=\"yellow\">"+input;
            }}});

context.setVertexLabelTransformer(labelTransformer);
John