Forums

Full Version: tree map demo showing all nodes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The TreeMap demo from the prefuse library mainly displays the leafs of the tree . In the case of a relative small tree you might want to display all nodes in the tree map. This demo shows one way to achieve this.

[attachment=105]

The implementation of this demo is based on the original prefuse TreeMap demo - only minor modifications had to be applied, including to specify a frame for the nodes and a change of the LabelLayout, so that the decorator text is shown in the upper left corner of the square:
Code:
public static class LabelLayout extends Layout {
  double spacing;
  public LabelLayout(String group,double spacing) {
    super(group);
     this.spacing=spacing;
  }
  public void run(double frac) {
    Iterator iter = m_vis.items(m_group);
    while ( iter.hasNext() ) {
      DecoratorItem item = (DecoratorItem)iter.next();        
      Rectangle2D boundsLabel = item.getBounds();
      VisualItem node = item.getDecoratedItem();
      Rectangle2D bounds = node.getBounds();        
      setX(item, null, bounds.getX()+boundsLabel.getWidth()/2.+spacing);
      setY(item, null, bounds.getY()+boundsLabel.getHeight()/2.+spacing);
    }
  }
} // end of inner class LabelLayout
Reference URL's