@@ -752,33 +752,33 @@ d3.layout.tree = function() {
752752 x1 = 0 , // max breadth
753753 y1 = 0 ; // max depth
754754
755- // vl is the previous sibling of v
756- function firstWalk ( v , vl ) {
757- var children = v . children ,
758- l , r , a ;
755+ function firstWalk ( node , previousSibling ) {
756+ var children = node . children ;
759757 if ( ! children ) {
760- if ( l = vl ) {
761- v . prelim = l . prelim + separation ( v , l ) ;
758+ if ( previousSibling ) {
759+ node . prelim = previousSibling . prelim + separation ( node , previousSibling ) ;
762760 }
763761 } else {
764- var childCount = children . length ;
765- l = children [ 0 ] ;
766- r = children [ childCount - 1 ] ;
767- a = l ; // default ancestor
768- var cl = null ; // previous sibling
769- for ( var i = 0 ; i < childCount ; i ++ ) {
770- var c = children [ i ] ;
771- firstWalk ( c , cl ) ;
772- a = apportion ( c , cl , a ) ;
773- cl = c ;
762+ var n = children . length ,
763+ firstChild = children [ 0 ] ,
764+ lastChild = children [ n - 1 ] ,
765+ ancestor = firstChild ,
766+ previousChild ,
767+ child ,
768+ i = - 1 ;
769+ while ( ++ i < n ) {
770+ child = children [ i ] ;
771+ firstWalk ( child , previousChild ) ;
772+ ancestor = apportion ( child , previousChild , ancestor ) ;
773+ previousChild = child ;
774774 }
775- d3_layout_treeShift ( v ) ;
776- var midpoint = .5 * ( l . prelim + r . prelim ) ;
777- if ( l = vl ) {
778- v . prelim = l . prelim + separation ( v , l ) ;
779- v . mod = v . prelim - midpoint ;
775+ d3_layout_treeShift ( node ) ;
776+ var midpoint = .5 * ( firstChild . prelim + lastChild . prelim ) ;
777+ if ( previousSibling ) {
778+ node . prelim = previousSibling . prelim + separation ( node , previousSibling ) ;
779+ node . mod = node . prelim - midpoint ;
780780 } else {
781- v . prelim = midpoint ;
781+ node . prelim = midpoint ;
782782 }
783783 }
784784 }
0 commit comments