我看到了其他一些类似的问题(例如:https://stackoverflow.com/questions/28771698/jgraphx-how-to-avoid-adding-edges-over-each-other#=) ..但他们没有解决我的问题。我有一个图形,它们在2个顶点之间有2个边缘,但是它们是重叠的...被绘制在另一个之上。 只是为了让你知道,我正在使用FastOrganicLayout和变形。 如何避免相互添加边缘?
private void initializeGraph(List<List> allListGraph){
mxStylesheet stylesheet = graph.getStylesheet();
Hashtable<String, Object> style = new Hashtable<>();
stylesheet.putCellStyle("ROUNDED", style);
Map<String, Object> vertexStyle = stylesheet.getDefaultVertexStyle();
vertexStyle.put(mxConstants.STYLE_FILLCOLOR, "#FFFFFF");
vertexStyle.put(mxConstants.STYLE_STROKECOLOR, "#000000");
vertexStyle.put(mxConstants.STYLE_AUTOSIZE, 1);
vertexStyle.put(mxConstants.STYLE_SPACING, "30");
vertexStyle.put(mxConstants.STYLE_ORTHOGONAL, "true");
vertexStyle.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE);
Map<String, Object> edgeStyle = stylesheet.getDefaultEdgeStyle();
edgeStyle.put(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL);
edgeStyle.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_CURVE);
edgeStyle.put(mxConstants.STYLE_ENDARROW, mxConstants.ARROW_CLASSIC);
//here I create my vertices and edges, for example:
try{
v = graph.insertEdge(parent, null, edgesList.get(i+2) + edgesList.get(i+3), from, to, "ROUNDED");
edgesvList.add(v);edgesvList.add(edgeID++);
graph.setCellsEditable(true);
graph.setAllowDanglingEdges(false);
graph.setAllowLoops(true);
graph.setAutoSizeCells(true);
graph.setPortsEnabled(true);
graph.setEnabled(true);
}
finally
{
graph.getModel().endUpdate();
}
getContentPane().add(graphComponent,BorderLayout.CENTER);
syslabel = new JLabel(systemInfo);
syslabel.setLocation(20, graphComponent.getHeight()-20);
syslabel.setVisible(true);
graphComponent.setConnectable(false);
new mxParallelEdgeLayout(graph).execute(graph.getDefaultParent());
mxIGraphLayout layout = new mxFastOrganicLayout(graph);
// layout graph
layout.execute(graph.getDefaultParent());
// set some properties
((mxFastOrganicLayout) layout).setForceConstant(300); // the higher, the more separated
((mxFastOrganicLayout) layout).setDisableEdgeStyle( true); // true transforms the edges and makes them direct lines
((mxFastOrganicLayout) layout).setMinDistanceLimit(40);
// layout using morphing
graph.getModel().beginUpdate();
try {
layout.execute(graph.getDefaultParent());
} finally {
mxMorphing morph = new mxMorphing(graphComponent, 20, 1.2, 20);
morph.addListener(mxEvent.DONE, new mxIEventListener() {
@Override
public void invoke(Object arg0, mxEventObject arg1) {
graph.getModel().endUpdate();
}
});
morph.startAnimation();
}