partition.nodes()

1,748 views
Skip to first unread message

Sean Murphy

unread,
Jul 14, 2011, 7:51:19 AM7/14/11
to d3-js
Is there a tutorial or written explanation of the hierarchical data
structures with d3?

When attempting to use partition.nodes() I get an error saying that
this message does not exist. I search the d3.layout.js file and don't
see any such method.

Thanks again!

Jason Davies

unread,
Jul 14, 2011, 7:59:00 AM7/14/11
to d3...@googlegroups.com
On Thu, Jul 14, 2011 at 04:51:19AM -0700, Sean Murphy wrote:
> Is there a tutorial or written explanation of the hierarchical data
> structures with d3?

You probably want to read:

- https://github.com/mbostock/d3/wiki/Hierarchy-Layout
- https://github.com/mbostock/d3/wiki/Partition-Layout

> When attempting to use partition.nodes() I get an error saying that
> this message does not exist. I search the d3.layout.js file and don't
> see any such method.

nodes() can only be called on layout instances, so you need to call
d3.layout.partition(...).nodes() not d3.layout.partition.nodes().

Hope that helps,
--
Jason Davies, http://www.jasondavies.com/

Jason Davies

unread,
Jul 14, 2011, 8:22:53 AM7/14/11
to d3...@googlegroups.com
On Thu, Jul 14, 2011 at 04:51:19AM -0700, Sean Murphy wrote:
> When attempting to use partition.nodes() I get an error saying that
> this message does not exist. I search the d3.layout.js file and don't
> see any such method.

By the way, it's defined here:
https://github.com/mbostock/d3/blob/master/src/layout/hierarchy.js#L90

d3_layout_hierarchyRebind is called by hierarchy layouts for
convenience, to bind various functions to the current layout, including
the "nodes" function.

Mallory Ketcheson

unread,
Mar 30, 2016, 1:44:29 PM3/30/16
to d3-js, ja...@jasondavies.com
I get the same error when trying to use Mike's icicle example:
var partition = d3.layout.partition()
    .size([width, height])
    .value(function(d) { return d.size; });

d3.json("data.json", function(error, root) {
  if (error) throw error;

  var nodes = d3.layout.partition().nodes(root);

  svg.selectAll(".node")
      .data(nodes)
    .enter().append("rect")
      .attr("class", "node")
      .attr("x", function(d) { return d.x; })
      .attr("y", function(d) { return d.y; })
      .attr("width", function(d) { return d.dx; })
      .attr("height", function(d) { return d.dy; })
      .style("fill", function(d) { return color((d.children ? d : d.parent).name); });

  svg.selectAll(".label")
      .data(nodes.filter(function(d) { return d.dx > 6; }))
    .enter().append("text")
      .attr("class", "label")
      .attr("dy", ".35em")
      .attr("transform", function(d) { return "translate(" + (d.x + d.dx / 2) + "," + (d.y + d.dy / 2) + ")rotate(90)"; })
      .text(function(d) { return d.name; });
});

How come I am unable to store the partition as a variable and use it after?
Reply all
Reply to author
Forward
0 new messages