Reputation: 115
I have read https://github.com/d3/d3-selection/blob/master/README.md#selection_filter. But I don't know why function doesn't work.
var bubble = d3.pack()
.size([diameter, diameter])
.padding(2);
var root = d3.hierarchy({"children": data.values});
var node = svg.selectAll(".node")
.data(bubble(root)
.filter(function(d) {return !d.children;}))
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) {
return "translate(" + d.x + "," + d.y + ")";
});
Upvotes: 1
Views: 6788
Reputation: 102198
Before you can pass your data to the pack()
function, you have to pass it to d3.hierarchy()
, which:
Constructs a root node from the specified hierarchical data.
So, given your data object:
var data = {
//Hierarchical data here
};
You have to pass it to d3.hierarchy()
:
var root = d3.hierarchy(data);
Then, you can use bubble
:
.data(bubble(root))
EDIT: Since you changed the title of your question, the problem is now clear: bubble(root)
returns an object, and you cannot use filter in an object. That's an array method.
Upvotes: 1