问题
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