0

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!

SPatil
  • 1,003
  • 8
  • 13

1 Answers1

0

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.

SPatil
  • 1,003
  • 8
  • 13
  • So you're saying that the only change you made was to replace your graph implementation? Please clarify, as that seems implausible based on how the classes work. – Joshua O'Madadhain Jan 05 '14 at 16:38
  • Yes, that is the only thing I changed. Actually you can use DelegateTree instead of OrderedKAryTree cause both implement the Forest, Graph and Tree interface. Of course their implementation is different, what DelegateTree does not have is the limit on the number of children of a node, that I had to take care of in my code. – SPatil Jan 08 '14 at 20:39