升级到d3.js v4.1.1后,此行:
d3.layout.tree()
产生错误:
Cannot read property 'tree' of undefined
看起来树形布局已从v4中删除了? https://github.com/d3/d3/blob/master/API.md
示例仍使用v3 API:
http://bl.ocks.org/mbostock/1093025
布局真的消失了还是重新命名了?
解决方法
似乎树布局刚刚重命名.看到:
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