@@ -350,7 +350,7 @@ d3.layout.partition = function() {
350350 node . dy = dy ;
351351 if ( children ) {
352352 var i = - 1 ,
353- n = ( children = children . slice ( ) . sort ( d3_layout_hierarchySort ) ) . length ,
353+ n = children . length ,
354354 c ,
355355 d ;
356356 dx /= node . value ;
@@ -378,6 +378,7 @@ d3.layout.partition = function() {
378378 return nodes ;
379379 }
380380
381+ partition . sort = d3 . rebind ( partition , hierarchy . sort ) ;
381382 partition . children = d3 . rebind ( partition , hierarchy . children ) ;
382383 partition . value = d3 . rebind ( partition , hierarchy . value ) ;
383384
@@ -647,7 +648,8 @@ function d3_layout_stackSum(p, d) {
647648 return p + d . y ;
648649}
649650d3 . layout . hierarchy = function ( ) {
650- var children = d3_layout_hierarchyChildren ,
651+ var sort = d3_layout_hierarchySort ,
652+ children = d3_layout_hierarchyChildren ,
651653 value = d3_layout_hierarchyValue ;
652654
653655 // Recursively compute the node depth and value.
@@ -670,6 +672,7 @@ d3.layout.hierarchy = function() {
670672 d . parent = node ;
671673 }
672674 }
675+ if ( sort ) c . sort ( sort ) ;
673676 node . value = v ;
674677 } else {
675678 node . value = value . call ( hierarchy , data , depth ) ;
@@ -683,6 +686,12 @@ d3.layout.hierarchy = function() {
683686 return nodes ;
684687 }
685688
689+ hierarchy . sort = function ( x ) {
690+ if ( ! arguments . length ) return sort ;
691+ sort = x ;
692+ return hierarchy ;
693+ } ;
694+
686695 hierarchy . children = function ( x ) {
687696 if ( ! arguments . length ) return children ;
688697 children = x ;
@@ -732,7 +741,7 @@ d3.layout.treemap = function() {
732741 if ( ! node . children ) return ;
733742 var rect = { x : node . x , y : node . y , dx : node . dx , dy : node . dy } ,
734743 row = [ ] ,
735- children = node . children . slice ( ) . sort ( d3_layout_hierarchySort ) ,
744+ children = node . children . slice ( ) , // copy-on-write
736745 child ,
737746 best = Infinity , // the best row score so far
738747 score , // the current row score
@@ -825,6 +834,7 @@ d3.layout.treemap = function() {
825834 return nodes ;
826835 }
827836
837+ treemap . sort = d3 . rebind ( treemap , hierarchy . sort ) ;
828838 treemap . children = d3 . rebind ( treemap , hierarchy . children ) ;
829839 treemap . value = d3 . rebind ( treemap , hierarchy . value ) ;
830840
0 commit comments