使用mxcirclelayout的jgrapht中directedweightedgraph中的重叠边

wtlkbnrh  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(255)

在已构建的图形上运行以下代码(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();
        }
    }

给我这个图表:

为了使边缘上的重叠文本可读,我试着 mxParallelEdgeLayout layout = new mxParallelEdgeLayout(graphAdapter); 与jgraphx的重叠边相同
但这给我带来了一个嫌疑犯

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]

它指向 ImageIO.write(image, "PNG", imgFile); 行。。使用mxcirclelayout效果很好。
我怎样才能使我的边缘变得易读?
为什么paralleledgelayout会破坏imageio.write?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题