Otherwise, the accessor should return an array of data elements representing the child nodes. If the accessor returns null, then the node is assumed to be a leaf node at the layout traversal terminates. The children accessor is first invoked for root node in the hierarchy. If children is not specified, returns the current children accessor function, which by default assumes that the input data is an object with a children array: function children(d) , If children is specified, sets the specified children accessor function. This method is useful for retrieving a set of link descriptions suitable for display, often in conjunction with the diagonal shape generator.
- source - the parent node (as described above).
- Each link is an object with two attributes:
Given the specified array of nodes, such as those returned by nodes, returns an array of objects representing the links from parent to child for each node. y - the computed y-coordinate of the node position.Īlthough the layout has a size in x and y, this represents an arbitrary coordinate system for example, you can treat x as a radius and y as an angle to produce a radial rather than Cartesian layout.
x - the computed x-coordinate of the node position.depth - the depth of the node, starting at 0 for the root.children - the array of child nodes, or null for leaf nodes.parent - the parent node, or null for the root.Several attributes are populated on each node: These layouts follow the same basic structure: the input argument to the layout is the root node of the hierarchy, and the output return value is an array representing the computed positions of all nodes. The tree layout is part of D3's family of ] layouts. Runs the tree layout, returning the array of nodes associated with the specified root node.
Like other classes in D3, layouts follow the method chaining pattern where setter methods return the layout itself, allowing multiple setters to be invoked in a concise statement.Ĭreates a new tree layout with the default settings: the default sort order is null the default children accessor assumes each input data is an object with a children array the default separation function uses one node width for siblings, and two node widths for non-siblings the default size is 1×1. That is: you can call the layout like any other function, and the layout has additional methods that change its behavior. Like most other layouts, the object returned by d3.ee is both an object and a function.
For example, a tree layout can be used to organize software classes in a package hierarchy: The tree layout produces tidy node-link diagrams of trees using the Reingold–Tilford “tidy” algorithm.