Menu

Layouts degrade when applied repeatedly

2005-12-16
2013-05-29
  • Nobody/Anonymous

    I have set up a simple UI that lets me choose from a number of JUNG layout algorithms, from a popup menu. This allows me to see how various layouts perform on the same graph. Initially I start out with a reasonably spread out yet random layout.

    Then I apply one of the layouts, say DAG. The nodes are rearranged. If I then apply the same layout again, the graph seems to become compressed within a part of the visible area. This continues as I apply the layout repeatedly. After just two or three executions, the layout is unusable.

    The same seems to happen if I choose different layout algorithms in succession.

    I suspect I may be doing something wrong in terms of the way I apply the layouts, the iterations, etc. Here's part of my code:

    Rectangle2D overallBounds = [get bounds from display]

            Layout layout;
            switch (layoutType) {
                case FRUCHTERMAN_REINGOLD:
                    layout = new FRLayout(g);
                    break;
                case CIRCLE:
                    layout = new CircleLayout(g);
                    break;
                case DAG:
                    layout = new DAGLayout(g);
                    break;
                case ISOM:
                    layout = new ISOMLayout(g);
                    break;
                case KAMADA_KAWAI:
                    layout = new KKLayout(g);
                    break;
                case STATIC:
                    layout = new StaticLayout(g);
                    break;
                default:
                    return;
            }
            layout.initialize(new Dimension((int) overallBounds.getWidth(), (int) overallBounds.getHeight()));

            if ( layoutType == KAMADA_KAWAI)
                ((KKLayout) layout).adjustForGravity();

            if ( layout.isIncremental() )
            {
                final int maxIterations = 10000;
                int numIterations = 0;
                while ( ! layout.incrementsAreDone() && numIterations < maxIterations )
                {
                    numIterations++;
                    layout.advancePositions();
                }
            }

    And the above code gets called each time a layout is selected from the popup menu.

    Should I be doing something differently above? Should I be using "layout.restart()" at some point in between?

    Any help will be much appreciated,
    Thank you.

     
    • Nobody/Anonymous

      Can anyone please help with this matter?

      If there is detailed documentation on how to apply the layouts, incremental and non-incremental, please let me know where I can find it.

      Thank you.

       
    • Tom Nelson

      Tom Nelson - 2005-12-19

      Have you looked at the source for the supplied
      demo called 'samples.graph.ShowLayouts'?
      From your description, it sounds like our demo
      does what you are trying to do.

      Tom

       
    • Nobody/Anonymous

      Thank you for the tip. I have looked at the ShowLayouts class, and from there the VisualizationViewer, VisualizationModel, DefaultVisualizationModel, Layout, AbstractLayout, etc. classes. I was able to glean some relevant information about how to apply the layouts, but am not fully satisfied: my interest is specifically in applying a Layout class, without visualization.

      In my case, I already have a different framework for visualization, but want to test the JUNG layout algorithms on my own datastructures. I have had some difficulty understanding the relevant portion of the Layout API and would appreciate any further guidance in that respect.

      I believe my problem (layouts deteriorating) stemmed from a mistake in how I specified the bounds when calling Layout.initialize(Dimension) - the bounds changed with each iteration and I believe that caused the repeated layouts to "shrink".

      I still observe a strange issue when applying the DAGLayout repeatedly - it seems the # of iterations drops from the first time I apply the layout (200 or more iterations), and there are zero iterations for every subsequent time the layout is applied.

       
      • Joshua O'Madadhain

        "my interest is specifically in applying a Layout class, without visualization"

        This should be easy enough: create the layout, initialize and advance it until it settles down, and then get the positions via the Layout/VertexLocationDecorator API calls. 

        "I still observe a strange issue when applying the DAGLayout repeatedly - it seems the # of iterations drops from the first time I apply the layout (200 or more iterations), and there are zero iterations for every subsequent time the layout is applied. "

        Since this code was contributed by one of our users (John Yesberg), the following is just an educated guess; you may want to ask John if you have more questions.

        My guess is that DAGLayout doesn't do anything after the first time is that its termination point is stable, i.e., further iterations will have no effect.  Then again, there may be something about your 'test rig' that I don't understand.

        Joshua

         

Log in to post a comment.