4

Problem

Earlier versions (1.x) of JGraphX offered the attribute layoutFromSinks in the mxHierarchicalLayout class. This isn't available anymore and from what I've seen hasn't been for a long time.

The problem of the layout difference is best explained in pictures:

Old JGraphX version, layout from sinks enabled, produces this:

enter image description here

Newer JGraph versions (most current I tried is 3.4.1.2) produce this:

enter image description here

As you can see, the old version produces a much cleaner result.

Question

Is this hierarchical layout also possible in the latest version of JGraphX and which settings do you need to apply to achieve the same layout?

Code

Here's example code that produced the above layouts

import java.awt.BorderLayout;

import javax.swing.JFrame;

import com.mxgraph.layout.mxIGraphLayout;
import com.mxgraph.layout.hierarchical.mxHierarchicalLayout;
import com.mxgraph.model.mxICell;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;

public class HierarchyLayoutExample extends JFrame {

    mxICell a,b,c,d,e,f,g,h;

    public HierarchyLayoutExample() {

        final mxGraph graph = new mxGraph();
        Object parent = graph.getDefaultParent();

        graph.getModel().beginUpdate();
        try {

            a = (mxICell) graph.insertVertex(parent, null, "a", 0, 0, 80, 30);
            b = (mxICell) graph.insertVertex(parent, null, "b", 0, 0, 80, 30);
            c = (mxICell) graph.insertVertex(parent, null, "c", 0, 0, 80, 30);
            d = (mxICell) graph.insertVertex(parent, null, "d", 0, 0, 80, 30);
            g = (mxICell) graph.insertVertex(parent, null, "g", 0, 0, 80, 30);
            h = (mxICell) graph.insertVertex(parent, null, "h", 0, 0, 80, 30);
            e = (mxICell) graph.insertVertex(parent, null, "e", 0, 0, 80, 30);

            graph.insertEdge(parent, null, "", a, b);
            graph.insertEdge(parent, null, "", a, c);
            graph.insertEdge(parent, null, "", c, d);
            graph.insertEdge(parent, null, "", e, d);
            graph.insertEdge(parent, null, "", g, a);
            graph.insertEdge(parent, null, "", b, d);
            graph.insertEdge(parent, null, "", h, e);

        } finally {
            graph.getModel().endUpdate();
        }

        // define layout
        mxHierarchicalLayout layout = new mxHierarchicalLayout(graph);
        // layout.setLayoutFromSinks(true); // <== not available anymore

        layout.execute(graph.getDefaultParent());

        mxGraphComponent graphComponent = new mxGraphComponent(graph);
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(graphComponent, BorderLayout.CENTER);

    }
    public static void main(String[] args) {
        HierarchyLayoutExample frame = new HierarchyLayoutExample();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(460, 400);
        frame.setVisible(true);
    }
}
Roland
  • 18,114
  • 12
  • 62
  • 93
  • As far as I see, there is no such option atm. You can have a look at `mxHierarchicalLayout.setFineTuning(false)`. If this doesn't fit you needs, I think you have to write your own `mxEdgeStyleFunction` and set it as the edgestyle to be used, then use `mxHierarchicalLayout.setDisableEdgeStyle(false)` – F. Lumnitz Jan 21 '16 at 12:03
  • Thanks, I already tried that. Didn't give the expected results. Currently I copied the layout code form the last version where it worked and use that one. – Roland Jan 21 '16 at 13:20

0 Answers0