Tree

detroit.tree() Tree

Builds a new tree layout with default settings.

Returns:

Tree object

Return type:

Tree

class detroit.hierarchy.tree.Tree

Tree layout

__call__(root: Node) Node

Lays out the specified root hierarchy, assigning the following properties on root and its descendants:

  • node.x - the x-coordinate of the node

  • node.y - the y coordinate of the node

The coordinates x and y represent an arbitrary coordinate system; for example, you can treat x as an angle and y as a radius to produce a radial layout. You may want to call root.sort before passing the hierarchy to the tree layout.

Parameters:

root (Node) – Root node

Returns:

Node organized as tree

Return type:

Node

set_separation(separation: Callable[[Node, Node], int]) Tree

Sets the separation accessor to the specified function and returns this tree layout.

Parameters:

separation (Callable[[Node, Node], int]) – Separation function which compares two nodes.

Returns:

Itself

Return type:

Tree

set_size(size: tuple[float, float]) Tree

Sets this tree layout’s size to the specified two-element array of numbers [width, height] and returns this tree layout. A layout size of None indicates that a node size will be used instead. The coordinates x and y represent an arbitrary coordinate system; for example, to produce a radial layout, a size of [360, radius] corresponds to a breadth of 360° and a depth of radius.

Parameters:

size (tuple[float, float]) – Tree layout’s size

Returns:

Itself

Return type:

Tree

set_node_size(node_size: tuple[float, float]) Tree

Sets this tree layout’s node size to the specified two-element array of numbers [width, height] and returns this tree layout. A node size of None indicates that a layout size will be used instead. When a node size is specified, the root node is always positioned at \((0, 0)\).

Parameters:

node_size (tuple[float, float]) – Tree layout’s node size

Returns:

Itself

Return type:

Tree