问题
While the below piece of code works find in d3v3, it fails in v4.
var nodes = tree.nodes(root).reverse(),
links = tree.links(nodes);
Uncaught TypeError: tree.nodes is not a function
What is the alternative for it in v4?
回答1:
import { hierarchy, tree } from 'd3-hierarchy'
// create a hierarchy from the root
const treeRoot = hierarchy(root)
tree(treeRoot)
// nodes
const nodes = treeRoot.descendants()
// links
const links = treeRoot.links()
来源:https://stackoverflow.com/questions/41087568/d3js-tree-nodes-is-not-a-function