Search code examples
javagraphjung

Q: How to change arrow position or remove it from an edge ? (JUNG)


What the question states.I have many arrows connecting to one Node and it looks very cluttered on the graph. Any way to relocate the arrows towards the center or remove them ?


Solution

  • By default, directed edges are rendered with arrowheads on them so that you can see the direction of the edge.

    If you don't want the arrowheads to be present at all:

    visualizationViewer.getRenderContext().setEdgeArrowPredicate(false);
    

    If you want the arrowheads to be present, but rendered in the middle of their respective edges instead of at their target:

    visualizationViewer.getRenderer()
        .getEdgeRenderer()
        .setEdgeArrowRenderingSupport(
            new CenterEdgeArrowRenderingSupport<>());
    

    If you want to use a different edge shape that shows the edge direction differently:

    visualizationViewer
        .getRenderContext()
        .setEdgeShapeTransformer(EdgeShape.wedge(10));
    

    Finally, if you don't want directed edges, then you can use an undirected graph. (The edges of SparseMultigraph are undirected by default.)

    These capabilities are demonstrated in PluggableRendererDemo, which is one of the samples available as part of the JUNG distribution. Note that these APIs are accurate for JUNG 2.1.*, but some things will be changing for the upcoming 3.0 release.