1

I saw some other similar questions (e.g.: https://stackoverflow.com/questions/28771698/jgraphx-how-to-avoid-adding-edges-over-each-other#=) ..but they didn't solve my problem. I have a graph with more them 2 edges between 2 vertices, but they are overlapping... being drawn above the other. Just to let you know, I'm using FastOrganicLayout and morphing. How can I avoid adding edges over each other?

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();
    }

0 Answers0