OrderedKAryTree rendered incorrectly (JUNG2)

106 views Asked by At

I have been working on a displaying AVL Tree operations graphically using JUNG2 (without any animations)

I am using OrderedKAryTree for the same. But there is some problem with the rendering. All the edges appear from root to the upper left corner of the frame. As shown in this screenshot

Here's my visualizer code

        vv = new VisualizationViewer<Integer, Integer>(
            new TreeLayout<Integer, Integer>(graph),
            new Dimension(500, 400));
        vv.setBackground(Color.white);
        vv.getRenderContext().setEdgeShapeTransformer(
            new EdgeShape.Line<Integer, Integer>());
        vv.getRenderContext().setVertexLabelTransformer(
            new ToStringLabeller<Integer>());

        frame.getContentPane().add(vv, BorderLayout.CENTER);
        frame.getContentPane().validate();

I have not been able to figure out why this is happening. Also, the same code works perfectly if I use DelegateTree although the ordering is not achieved.

Please help. Thanks in advance!

1

There are 1 answers

2
SPatil On BEST ANSWER

Found out the solution. Instead of using OrderedKAryTree use DelegateTree with DirectedOrderedSparceGraph

Here is how the graph should be initialized:

DelegateTree<V, E> graph = new DelegateTree<V, E>(
    new DirectedOrderedSparseMultigraph<V, E>());

V and E can be any Object.

This does not solve the problem of OrderedKAryTree getting rendered incorrectly but it can surely help you display a binary search tree.