How to prevent default sorting of children nodes in d3.layout.partition?

564 Views Asked by At

d3.layout.partition automatically sorts children nodes in descending order by default. I'm using an icicle plot to show a binary tree where I want to keep the original tree structure without any node reordering. How do I create an array of nodes from my tree without the sort? My code sets the nodes as follows:

 var partition = d3.layout.partition()
.size([width, height])
.value(function(d) { return d.size; });
 var nodes= partition.nodes(root);
1

There are 1 best solutions below

0
On BEST ANSWER

According to the API, when using partition.sort([comparator]):

A null comparator disables sorting and uses tree traversal order.

Thus, it should be:

var partition = d3.layout.partition()
    .size([width, height])
    .value(function(d) { return d.size; })
    .sort(null);