overlapping edges in DirectedWeightedGraph in JGraphT using mxCircleLayout

家住魔仙堡 提交于 2021-02-11 16:38:30

问题


Running below code on an already constructed Graph (usind ArbEdge.class as Edges)

    Graph<String, ArbEdge> graph = new DefaultDirectedWeightedGraph<>(ArbEdge.class);

    public void pngGraph() {

        JGraphXAdapter<String, ArbEdge> graphAdapter =
                new JGraphXAdapter<String, ArbEdge>(this.getGraph());

        mxIGraphLayout layout = new mxCircleLayout(graphAdapter);
        // mxParallelEdgeLayout layout = new mxParallelEdgeLayout(graphAdapter);
        layout.execute(graphAdapter.getDefaultParent());

        BufferedImage image =
                mxCellRenderer.createBufferedImage(graphAdapter, null, 2.5, Color.WHITE, true, null);
        try {
            ImageIO.write(image, "PNG", imgFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

gets me this Graph:

In order to make the overlapping text on the edges readable i tried mxParallelEdgeLayout layout = new mxParallelEdgeLayout(graphAdapter); as suggested in Overlapping edges with JGraphx

but this brought me a suspect

java.lang.IllegalArgumentException: image == null!
    at java.desktop/javax.imageio.ImageTypeSpecifier.createFromRenderedImage(ImageTypeSpecifier.java:925) ~[na:na]
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
    |_ checkpoint ⇢ HTTP GET "/png" [ExceptionHandlingWebHandler]

which points to the ImageIO.write(image, "PNG", imgFile); line.. which works just fine using mxCircleLayout.

How can i make my edges human-readable?

Why does ParallelEdgeLayout break the ImageIO.write?

来源:https://stackoverflow.com/questions/65134394/overlapping-edges-in-directedweightedgraph-in-jgrapht-using-mxcirclelayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!