jungjung2

Create bidirectional arrows in JUNG


Is it possible to create bidirectional arrows in JUNG using FRLayout? Ideally, is it possible to have an algorithm that uses these arrows (end-points are arrowheads at both ends) for cases where both a->b and b<-a?

I think it might be related to

 Renderer.Edge<String, String> edgeRenderer = 
        vv.getRenderer().getEdgeRenderer();

but can't see how to get the shapes of the arrowheads


Solution

  • You could do something like this hack to make (in this case) Curved edges overlay each other:

            vv.getRenderContext().setEdgeShapeTransformer(new Function<String, Shape> () {
                @Override
                public Shape apply(String edge) {
                    Pair<String> endpoints = graph.getEndpoints(edge);
                    float controlY = 60.f;
                     // use some hacked 'ordering' of the endpoint nodes so that the curve for A->B is on the same side as the curve from B->A
                    if (endpoints.getFirst().toString().compareTo(endpoints.getSecond().toString()) < 0) {
                        controlY *= -1;
                    }
                    return new QuadCurve2D.Float(0.0f, 0.0f, 0.5f, controlY, 1.0f, 0.0f);
                }
            });