Search code examples
javagraphjung

Java JUNG Graph: Some edges miss arrows


I've made a graph with StaticLayout and changed shapes\colors of vertices. I didn't transform anything related to edges. All edges are directed, but some of them miss arrows! How could that happen?

screenshot

Graph Visualization code:

    Layout<Object, String> layout = new StaticLayout<Object, String>(graphProvider.graphFor(market),new MarketVertexLayoutTransformer(market,panel.getMarketGraphPane().getSize() )) ;
    layout.setSize(panel.getMarketGraphPane().getSize());
    VisualizationViewer<Object,String> graphPanel = new VisualizationViewer<Object,String>(layout);
    graphPanel.getRenderContext().setVertexShapeTransformer(new MarketVertexShapeTransformer());
    graphPanel.getRenderContext().setVertexFillPaintTransformer(new MarketVertexColorTransformer());
    panel.getMarketGraphPane().add(graphPanel, BorderLayout.CENTER);
    panel.getMarketGraphPane().revalidate();

Graphs is

graph = new DirectedSparseGraph<Object, String>();

and Edges are created like that

   graph.addEdge(bundle.getGood()+"->"+transformation,bundle.getGood(),transformation);
   graph.addEdge(transformation+"->"+bundle.getGood(),transformation,bundle.getGood());

Thanks


Solution

  • The arrow placement is done by subdividing the edge until the far segment is enclosed in the vertex shape, then moving back one. If the far endpoint is not inside the vertex shape when the operation starts, there should be an exception thrown. You chose the correct solution, which is to center your vertex shapes on the origin before they are translated into place. Tom Nelson