I have a dataset such that when sorted in ascending order the circles end up 'stacked' but appear properly distributed when using null or descending sort order.
Complete example is here: http://jsfiddle.net/SXLHx/3/.
Anyone have a suggestion?
sortItems = function(a,b) {
var str,result;
switch(sortOrder%3){
case 0:
str = 'ascending';
result = a.size - b.size;
break;
case 1:
str = 'descending';
result = b.size - a.size;
break;
default:
str = 'null';
result = null;
}
document.getElementById("sortLbl").innerHTML = str;
return result;
};
pack = d3.layout.pack().sort(sortItems);
Some additional info:
I found that if I remove at least two of the blocks entries that have the value 0 (didn't matter which two but it had to be two) the layout is fine. http://jsfiddle.net/SXLHx/4/
Also, applying a filter to not append circles with 0 value like so:
// Create circles
node.append("circle")
.filter(function(d){return d.size > 0;})
.attr("r",function(d){return d.r;});
does not correct the layout issue. Maybe I'm filtering incorrectly?