d3js partition incorrect

26 views
Skip to first unread message

andrew solis

unread,
Jul 17, 2017, 5:56:05 PM7/17/17
to d3-js

Hey all,


      I'm trying to update the bilevel partition (here) to use d3js v4. I am pretty close, but am running into a bit a trouble with calculating the arcs. I have a jsfiddle of the issue I'm running into with the partition of the dataset (JSFiddle). The incorrect partition should look like this: 


While the correct partition is something more along the lines of this:



There was no where I could tell for sure, but I'm assuming for partition

d.x and d.dx


were changed in d3.js v4 to be


d.x0 and d.x1

accordingly. Also in d3.js v3 for his bilevel partition example he is overriding the value and children function for the partition like so

  partition
     
.children(function(d, depth) { return depth < 2 ? d._children : null; })
     
.value(function(d) { return d.sum; });

Whereas d3.js v4 doesn't have that. He also precomputes the value for each node and stores it in a new variable for each node called .sum
  partition
     
.value(function(d) { return d.size; })
     
.nodes(root)
     
.forEach(function(d) {
        d
._children = d.children;
        d
.sum = d.value;
        d
.key = key(d);
        d
.fill = fill(d);
     
});

I am doing something similar here:
  root = d3.hierarchy( root )
           
.sum( function ( d )
           
{
               
return d.size;
           
})
           
.each( function ( d )
           
{
               d
.data._children = d.children;
               d
._children = d.children;
               d
.key  = key( d );
               d
.fill = fill( d );


           
});

But I'm not changing the value function since you can no longer do that for partitions in v4 of D3.js.

If anyone has any advice on how to tackle this problem it would greatly be appreciated, and if I explained something incorrect or not well please let me know.

Thanks,

Andrew S
Reply all
Reply to author
Forward
0 new messages