title: Jung, Layout for large vertices overlap and graph appears in strange location
body: <p>I am trying to use Jung for a project and to get the look/behavior I want I am starting with some test data. </p>
  
  <p>The idea is to have very Large Vertices with labels on top of the Verticies shapes. The data for the graph will be generated at runtime so I cannot do a static layout.</p>
  
  <p>How do I layout the graph so that the Vertices do not overlap, but are still large enough so that the labels fit inside (real label will have longer strings 20-30 chars). I have tried using SpringLayout but the nodes still overlap, additionally the layout keeps jiggling (which is annoying).</p>
  
  <p>I also tried FRLayout while increassing the Repulsion multiplier, however after the number gets large enough it just creates a circle with the Vertices overlapping.</p>
  
  <p>If I Zoom in using the mouse gestures the nodes seem to separate and I get a view closer to what I want. So maybe the solution involves zooming in at initialization, just not sure exactly how to do that and how to decide how much to zoom as it may be dependent on the number of nodes.</p>
  
  <p>In general my data will have a small number of nodes (less then 50 and more commonly less then 10). However it is data driven so I don't have total control over those sizes.</p>
  
  <p>Finally when the graph does show up it is also partially off the screen. Ideally it would render toward the top left portion of the viewable area. Is there a way to control that?</p>
  
  <p>Below is the sample class I am working with to better show what I mean (trimmed for release).</p>
  
  <pre><code>import edu.uci.ics.jung.graph.Graph;
  import edu.uci.ics.jung.graph.util.TestGraphs;
  import edu.uci.ics.jung.visualization.VisualizationViewer;
  import edu.uci.ics.jung.algorithms.layout.AbstractLayout;
  import edu.uci.ics.jung.algorithms.layout.SpringLayout;
  import edu.uci.ics.jung.visualization.GraphZoomScrollPane;
  import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
  import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
  import edu.uci.ics.jung.visualization.decorators.AbstractVertexShapeTransformer;
  import edu.uci.ics.jung.visualization.decorators.EdgeShape;
  import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
  import java.awt.BorderLayout;
  import java.awt.Color;
  import org.apache.commons.collections15.Transformer;
  import org.apache.commons.collections15.functors.ConstantTransformer;
  import edu.uci.ics.jung.visualization.picking.PickedState;
  import edu.uci.ics.jung.visualization.renderers.DefaultVertexLabelRenderer;
  import edu.uci.ics.jung.visualization.renderers.GradientVertexRenderer;
  import edu.uci.ics.jung.visualization.renderers.VertexLabelAsShapeRenderer;
  import java.awt.*;
  
      public class IDRelationshipGraphPanel extends javax.swing.JPanel
  {
      private final VisualizationViewer&lt;Integer,Number&gt; vv;
      protected Transformer&lt;Integer,String&gt; vs;
      protected DefaultModalGraphMouse&lt;Integer, Number&gt; gm;
      protected AbstractLayout layout;
      protected VertexShapeSizeAspect&lt;Integer,Number&gt; vssa;
  
      public IDRelationshipGraphPanel()
      {
  
      Graph&lt;? extends Object, ? extends Object&gt; g = TestGraphs.getOneComponentGraph(); 
  
      layout = new SpringLayout( g) ;       
      vv= new VisualizationViewer&lt;Integer,Number&gt;(layout);
      GraphZoomScrollPane scrollPane = new GraphZoomScrollPane(vv);
  
      gm = new DefaultModalGraphMouse&lt;Integer, Number&gt;();
      vv.setGraphMouse(gm);                
      add(scrollPane, BorderLayout.CENTER);
  
      PickedState&lt;Integer&gt; picked_state = vv.getPickedVertexState();
  
      VertexLabelAsShapeRenderer&lt;Integer, Number&gt; vlasr = new VertexLabelAsShapeRenderer&lt;Integer, Number&gt;(vv.getRenderContext());
  
      vv.getRenderContext().setVertexShapeTransformer(vlasr);
      vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.red));
      vv.getRenderContext().setEdgeStrokeTransformer(new ConstantTransformer(new BasicStroke(2.5f)));
  
      // customize the renderer
      vv.getRenderer().setVertexRenderer(new GradientVertexRenderer&lt;Integer, Number&gt;( new Color(175,224,228), new Color(133,170,173), true));
      vv.getRenderer().setVertexLabelRenderer(vlasr);
  
      vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller&lt;Integer&gt;());
      vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line&lt;Integer, Number&gt;());                            
  
      vssa = new VertexShapeSizeAspect&lt;Integer,Number&gt;();
      vv.getRenderContext().setVertexShapeTransformer(vssa);
  
      vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
      vv.getRenderContext().setArrowDrawPaintTransformer(new ConstantTransformer(Color.black));        
      }
  
      private final static class VertexShapeSizeAspect&lt;V,E&gt;
      extends AbstractVertexShapeTransformer &lt;V&gt;
      implements Transformer&lt;V,Shape&gt;  {
  
      public VertexShapeSizeAspect()
      {
          setSizeTransformer(new Transformer&lt;V,Integer&gt;()
                  {
                      public Integer transform(V v) 
                      {
                      return 150;
                      }
                  });
          setAspectRatioTransformer(new Transformer&lt;V,Float&gt;() 
                  {
                      public Float transform(V v) 
                      {
                      return 1.0f;
                      }
                  });                                                                
      }
  
      public Shape transform(V v){return factory.getEllipse(v);}
      } 
  }
  </code></pre>
  
  <p>Overlapping Verticies with Spring Layout
  <img src="https://i.stack.imgur.com/3tmPc.png" alt="Overlapping Verticies with Spring Layout"></p>
  
  <p>Zoom in of Spring Layout appears better
  <img src="https://i.stack.imgur.com/8S5m2.png" alt="Zoom in of Spring Layout appears better"></p>