Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3js tree.nodes() is not a function

Tags:

d3.js

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?

like image 868
Mopparthy Ravindranath Avatar asked Dec 11 '16 15:12

Mopparthy Ravindranath


People also ask

What does D3 tree do?

The Tree Layout Explained Rather, it's one type of D3's family of hierarchical layouts. Other layout types include cluster and treemap. The tree layout produces a “node-link” diagram that lays out the connections among nodes in a way that displays the relationship of one node to another in a parent-child fashion.

How will you invoke the link method while constructing a tree layout using D3?

In the update() function, links = d3. layout. tree(). links(nodes); is 'selecting' the nodes in the tree and their specified links in the JSON file.


1 Answers

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()
like image 167
Paul S Avatar answered Sep 28 '22 01:09

Paul S