d3.js v4 d3.layout.tree has been removed?

2020-06-09 08:07发布

问题:

After upgrading to d3.js v4.1.1, this line:

d3.layout.tree()

produces an error:

Cannot read property 'tree' of undefined

It seems like the tree layout has been removed from v4? https://github.com/d3/d3/blob/master/API.md

The examples still use the v3 API: http://bl.ocks.org/mbostock/1093025

Is the layout really gone or has it been renamed?

回答1:

As of D3 v4.0 (June 2016), the tree layout has been renamed. See:

https://github.com/d3/d3/blob/master/CHANGES.md#hierarchies-d3-hierarchy

Pursuant to the great namespace flattening:

  • d3.layout.cluster ↦ d3.cluster
  • d3.layout.hierarchy ↦ d3.hierarchy
  • d3.layout.pack ↦ d3.pack
  • d3.layout.partition ↦ d3.partition
  • d3.layout.tree ↦ d3.tree
  • d3.layout.treemap ↦ d3.treemap


标签: d3.js