D3.js node.height Property
Last Updated :
23 Sep, 2020
The node.height property in D3.js returns the greatest distance from the given node to a descendant leaf node.
Syntax:
node.height
Return Value: This property returns the greatest distance from the given node to a descendant leaf node
Example 1: In this example, for the root node to the leaf node the greatest distance is 1, for the leaf node the greatest distance is 0.
HTML
<!DOCTYPE html>
< html >
< head >
< meta charset = "utf-8" >
< script src =
</ script >
</ head >
< body >
< script >
var data = {
"name":"GeeksforGeeks",
"about":"Computer Science Portal",
"children":[
{"name":"GFG1"},
{"name":"GFG2"},
{"name":"GFG3"},
{"name":"GFG4"}
]
}
var root = d3.hierarchy(data);
console.log("Height of root node is : ",
root.height);
console.log("Height of first children node is : ",
root.children[0].height);
</ script >
</ body >
</ html >
|
Output:
Example 2: In this example, the hierarchy is not having any child so height is 0.
HTML
<!DOCTYPE html>
< html >
< head >
< meta charset = "utf-8" >
< script src =
</ script >
</ head >
< body >
< script >
var data = {"name":"GFG1"}
var root = d3.hierarchy(data);
console.log("Height of this node is :",
root.height);
</ script >
</ body >
</ html >
|
Output:
Share your thoughts in the comments
Please Login to comment...