title: JUNG2 layout problems: resultant graphs end up too wide
body: <p>I have been working on JUNG2 for a while now, trying to visualize a pretty complicated hierarchy of a set of objects. Unfortunately, this hierarchy is not really like a tree in the sense that:</p>
  
  <ol>
  <li>some nodes will have multiple parents. Furthermore, these parents could be at different branches of the tree. </li>
  <li>some nodes might have duplicates (this is has to be allowed, I cant just ignore them)</li>
  </ol>
  
  <p>As of now I am using a <code>SparseGraph</code>; put all nodes in the graph, draw sub/super relationships with directed, and duplicates as undirected edges between nodes. Then following the <a href="http://jung.sourceforge.net/applet/mstdemo.html" rel="nofollow noreferrer">MinimumSpanningTreeDemo</a> source code, I create a <code>MinimumSpanningTreeForest2</code> object, and send the <code>Forest</code> to a <code>TreeLayout</code>. Long story short, I get the layouts however they are about 15000 pixels wide! Since I don't use these graphs in an interactive manner but rather as static images, this is simply not feasible for use in reports. </p>
  
  <p>I realized that the node labels take quite a bit of space if there are too many nodes that are side-by-side, so I figured that I could rotate the labels and have them vertical instead. This has failed miserably, I manage to rotate labels using a custom class that extends <code>DefaultVertexLabelRenderer</code>, but when I set rotation to <code>Math.PI/2</code> then I simply see no labels! So here are my questions: </p>
  
  <ol>
  <li>Is it possible to force the layout to be slimmer? I would like to make something like a dendrogram, which is <a href="https://stackoverflow.com/q/2195835/328725">claimed to be possible using JUNG2</a>. Is this really possible? In that case how? </li>
  <li>Is there a miss in my thinking that it should be possible to render the node labels vertically? I tried to change the anchor point in the <code>VertexLabelAsShapeRenderer</code> class but still no joy. Speaking of matter; the connection between <code>Renderer</code>s <code>RendererContext</code> and the actual rendered objects is really fuzzy. There are a lot of classes and I'm having hard times figuring out which ones are actually used to render. For instance <code>BasicVertexLabelRenderer</code> seems like it's not used at all by default. Thus the whole positioning of labels is just mystical... </li>
  </ol>
  
  <p>I know that JUNG developers have put hours of hard work into the library and I would hate to sound bitter or unthankful, but I really think there's a long gap between <a href="http://www.grotto-networking.com/JUNG/JUNG2-Tutorial.pdf" rel="nofollow noreferrer">this tutorial</a> and figuring out how the demos are written and how the rendering works. </p>
  
  <p>In any case; here's the bit of my code where the graph is created:</p>
  
  <pre><code>public void visualizeGraph(File saveFolder){
  
      MinimumSpanningForest2&lt;PHGNode, PHGEdge&gt; prim = new MinimumSpanningForest2&lt;PHGNode, PHGEdge&gt;(
              g,  new DelegateForest&lt;PHGNode, PHGEdge&gt;(), DelegateTree.&lt;PHGNode, PHGEdge&gt;getFactory(),
                  new ConstantTransformer(1.0));
  
      Forest&lt;PHGNode, PHGEdge&gt; tree = prim.getForest();
  
      Layout&lt;PHGNode, PHGEdge&gt; layout = new TreeLayout&lt;PHGNode, PHGEdge&gt;(tree);
      // custom visualization viewer that allows writing to disk
      final WritingVisualizationViewer&lt;PHGNode, PHGEdge&gt; vv = new WritingVisualizationViewer&lt;PHGNode, PHGEdge&gt;(layout,layout.getSize());
  
      // this class extends VertexLabelAsShapeRenderer and supplies means of fiddling with label coordinates
      VerticalVertexLabelAsShapeRenderer&lt;PHGNode,PHGEdge&gt; vlasr = 
              new VerticalVertexLabelAsShapeRenderer&lt;PHGNode,PHGEdge&gt;(vv.getRenderContext()); 
  
      vv.getRenderContext().setVertexLabelTransformer(
              new ChainedTransformer&lt;PHGNode,String&gt;(new Transformer[]{
                      new ToStringLabeller&lt;PHGEdge&gt;(),new Transformer&lt;String,String&gt;() {
                              public String transform(String input) { return input;       }}})); 
  
      //  Change the background of node labels so that they appear transparent
      Transformer&lt;PHGNode,Paint&gt; vertexPaint = new Transformer&lt;PHGNode,Paint&gt;() {
          public Paint transform(PHGNode n) { return vv.getBackground();  }
      };
  
          // extends DefaultVertexLabelRendeder to provide rotation of labels
      VerticalVertexLabelRenderer vvlr = new VerticalVertexLabelRenderer();
      vv.getRenderContext().setVertexLabelRenderer(vvlr); 
  
      vv.getRenderContext().setVertexFontTransformer(new VertexFontTransformer&lt;PathwayHierarchyGraph.PHGNode&gt;()); 
      vv.getRenderContext().setVertexShapeTransformer(vlasr); 
      vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
      vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.BentLine&lt;PHGNode, PHGEdge&gt;()); 
      vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
  
  
      //printGraphStats(tree);
      vv.writeToDisk(saveFolder,"hierarchyTree.png");
  
  
  }
  </code></pre>