private void arrangeChildVertically( NodeItem parent ) { double maxW = 0; for( int i = 0; i < parent.getChildCount(); i++ ) { NodeItem node = (NodeItem) parent.getChild( i ); Rectangle2D bounds = node.getBounds(); maxW = Math.max( maxW, bounds.getWidth() ); } for( int i = 0; i < parent.getChildCount(); i++ ) { NodeItem node = (NodeItem) parent.getChild( i ); Rectangle2D bounds = node.getBounds(); node.setBounds( bounds.getX(), bounds.getY(), maxW, bounds.getHeight() ); } }
private void arrangeChildHorizontally( NodeItem parent ) { double maxH = 0; for( int i = 0; i < parent.getChildCount(); i++ ) { NodeItem node = (NodeItem) parent.getChild( i ); Rectangle2D bounds = node.getBounds(); maxH = Math.max( maxH, bounds.getHeight() ); } for( int i = 0; i < parent.getChildCount(); i++ ) { NodeItem node = (NodeItem) parent.getChild( i ); Rectangle2D bounds = node.getBounds(); node.setBounds( bounds.getX(), bounds.getY(), bounds.getWidth(), maxH ); } } }
/** * Compute the tree map layout. */ private void layout(NodeItem p, Rectangle2D r) { // create sorted list of children Iterator childIter = p.children(); while ( childIter.hasNext() ) m_kids.add(childIter.next()); Collections.sort(m_kids, s_cmp); // do squarified layout of siblings double w = Math.min(r.getWidth(),r.getHeight()); squarify(m_kids, m_row, w, r); m_kids.clear(); // clear m_kids // recurse childIter = p.children(); while ( childIter.hasNext() ) { NodeItem c = (NodeItem)childIter.next(); if ( c.getChildCount() > 0 && c.getDouble(AREA) > 0 ) { updateArea(c,r); layout(c, r); } } }
/** * Computes relative measures of the angular widths of each * expanded subtree. Node diameters are taken into account * to improve space allocation for variable-sized nodes. * * This method also updates the base angle value for nodes * to ensure proper ordering of nodes. */ private double calcAngularWidth(NodeItem n, int d) { if ( d > m_maxDepth ) m_maxDepth = d; double aw = 0; Rectangle2D bounds = n.getBounds(); double w = bounds.getWidth(), h = bounds.getHeight(); double diameter = d==0 ? 0 : Math.sqrt(w*w+h*h) / d; if ( n.isExpanded() && n.getChildCount() > 0 ) { Iterator childIter = n.children(); while ( childIter.hasNext() ) { NodeItem c = (NodeItem)childIter.next(); aw += calcAngularWidth(c,d+1); } aw = Math.max(diameter, aw); } else { aw = diameter; } ((Params)n.get(PARAMS)).width = aw; return aw; }
/** * Compute the layout. * @param n the root of the current subtree under consideration * @param r the radius, current distance from the center * @param theta1 the start (in radians) of this subtree's angular region * @param theta2 the end (in radians) of this subtree's angular region */ protected void layout(NodeItem n, double r, double theta1, double theta2) { double dtheta = (theta2-theta1); double dtheta2 = dtheta / 2.0; double width = ((Params)n.get(PARAMS)).width; double cfrac, nfrac = 0.0; Iterator childIter = sortedChildren(n); while ( childIter != null && childIter.hasNext() ) { NodeItem c = (NodeItem)childIter.next(); Params cp = (Params)c.get(PARAMS); cfrac = cp.width / width; if ( c.isExpanded() && c.getChildCount()>0 ) { layout(c, r+m_radiusInc, theta1 + nfrac*dtheta, theta1 + (nfrac+cfrac)*dtheta); } setPolarLocation(c, n, r, theta1 + nfrac*dtheta + cfrac*dtheta2); cp.angle = cfrac*dtheta; nfrac += cfrac; } }
NodeItem n = (NodeItem)iter.next(); double area = 0; if ( n.getChildCount() == 0 ) { area = n.getSize(); ++leafCount;
for( int i = 0; i < node.getChildCount(); i++ )
base = normalize(Math.atan2(p.getY()-n.getY(), p.getX()-n.getX())); int cc = n.getChildCount(); if ( cc == 0 ) return null;
if ( n.getChildCount() == 0 || !expanded ) // is leaf