d3.hierarchy()

d3.hierarchy(data[, children])

Constructs a root node from the specified hierarchical data. The specified data must be an object representing the root node. For example:

{
  "name": "Eve",
  "children": [
    {
      "name": "Cain"
    },
    {
      "name": "Seth",
      "children": [
        {
          "name": "Enos"
        },
        {
          "name": "Noam"
        }
      ]
    },
    {
      "name": "Abel"
    },
    {
      "name": "Awan",
      "children": [
        {
          "name": "Enoch"
        }
      ]
    },
    {
      "name": "Azura"
    }
  ]
}

The specified children accessor function is invoked for each datum, starting with the root data, and must return an array of data representing the children, or null if the current datum has no children. If children is not specified, it defaults to:

function children(d) {
  return d.children;
}

The returned node and each descendant has the following properties:

  • node.data - the associated data, as specified to the constructor
  • node.depth - zero for the root node, and increasing by one for each descendant generation
  • node.height - zero for leaf nodes, and the greatest distance from any descendant leaf for internal nodes
  • node.parent - the parent node, or null for the root node
  • node.children - an array of child nodes, if any; undefined for leaf nodes.
  • node.value - the summed value of the node and its descendants; optional, set by node.sum.

This method can also be used to test if a node is an instanceof d3.hierarchy and to extend the node prototype.

doc_D3_Js
2016-11-24 10:26:43
Comments
Leave a Comment

Please login to continue.