Treemap

detroit.treemap() TreeMap

Builds a new treemap layout with default settings.

Returns:

TreeMap object

Return type:

TreeMap

class detroit.hierarchy.treemap.treemap.TreeMap

TreeMap layout

__call__(root: Node) Node

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

  • node.x0 - the left edge of the rectangle

  • node.y0 - the top edge of the rectangle

  • node.x1 - the right edge of the rectangle

  • node.y1 - the bottom edge of the rectangle

You must call root.sum before passing the hierarchy to the treemap layout. You probably also want to call root.sort to order the hierarchy before computing the layout.

Parameters:

root (Node) – Root node

Returns:

Node organized as treemap

Return type:

Node

set_tile(tile: Callable[[Node, float, float, float, float], None]) TreeMap

Sets this treemap layout’s tile and returns this treemap layout.

Available treemap tiles:

Parameters:

tile (Callable[[Node, float, float, float, float], None]) – Tile function

Returns:

Itself

Return type:

TreeMap

set_round(round_value: bool) TreeMap

If round is specified, enables or disables rounding according to the given boolean and returns this treemap layout.

Parameters:

round_value (bool) – Round value

Returns:

Itself

Return type:

TreeMap

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

If size is specified, sets this treemap layout’s size to the specified two-element array of numbers [width, height] and returns this treemap layout.

Parameters:

size (tuple[float, float]) – Size values

Returns:

Itself

Return type:

TreeMap

set_padding(padding: Callable[[Node], float] | float) TreeMap

Sets the inner and outer padding to the specified number or function and returns this treemap layout.

Parameters:

padding (Callable[[Node], float] | float) – Padding function or constant padding value

Returns:

Itself

Return type:

TreeMap

set_padding_inner(padding_inner: Callable[[Node], float] | float) TreeMap

Sets the inner padding to the specified number or function and returns this treemap layout. If padding_inner is a function, it is invoked for each node with children, being passed the current node. The inner padding is used to separate a node’s adjacent children.

Parameters:

padding_inner (Callable[[Node], float] | float) – Inner padding function or constant inner padding value

Returns:

Itself

Return type:

TreeMap

set_padding_outer(padding_outer: Callable[[Node], float] | float) TreeMap

Sets the top, right, bottom and left padding to the specified number or function and returns this treemap layout.

Parameters:

padding_outer (Callable[[Node], float] | float) – Outer padding function or constant outer padding value

Returns:

Itself

Return type:

TreeMap

set_padding_top(padding_top: Callable[[Node], float] | float) TreeMap

Sets the top padding to the specified number or function and returns this treemap layout. If padding_top is a function, it is invoked for each node with children, being passed the current node. The top padding is used to separate the top edge of a node from its children.

Parameters:

padding_top (Callable[[Node], float] | float) – Top padding function or constant top padding value

Returns:

Itself

Return type:

TreeMap

set_padding_right(padding_right: Callable[[Node], float] | float) TreeMap

Sets the right padding to the specified number or function and returns this treemap layout. If padding_right is a function, it is invoked for each node with children, being passed the current node. The right padding is used to separate the right edge of a node from its children.

Parameters:

padding_right (Callable[[Node], float] | float) – Right padding function or constant right padding value

Returns:

Itself

Return type:

TreeMap

set_padding_bottom(padding_bottom: Callable[[Node], float] | float) TreeMap

Sets the bottom padding to the specified number or function and returns this treemap layout. If padding_bottom is a function, it is invoked for each node with children, being passed the current node. The bottom padding is used to separate the bottom edge of a node from its children.

Parameters:

padding_bottom (Callable[[Node], float] | float) – Bottom padding function or constant bottom padding value

Returns:

Itself

Return type:

TreeMap

set_padding_left(padding_left: Callable[[Node], float] | float) TreeMap

Sets the left padding to the specified number or function and returns this treemap layout. If padding_left is a function, it is invoked for each node with children, being passed the current node. The left padding is used to separate the left edge of a node from its children.

Parameters:

padding_left (Callable[[Node], float] | float) – Left padding function or constant left padding value

Returns:

Itself

Return type:

TreeMap

Treemap tiling

detroit.treemap_binary(parent: Node, x0: float, y0: float, x1: float, y1: float)

Recursively partitions the specified nodes into an approximately-balanced binary tree, choosing horizontal partitioning for wide rectangles and vertical partitioning for tall rectangles.

Parameters:
  • parent (Node) – Parent node

  • x0 (float) – X-coordinate rectangular edge

  • y0 (float) – Y-coordinate rectangular edge

  • x1 (float) – X-coordinate rectangular edge

  • y1 (float) – Y-coordinate rectangular edge

detroit.treemap_dice(parent: Node, x0: float, y0: float, x1: float, y1: float)

Divides the rectangular area specified by \(x_0:, :math:`y_0\), \(x_1\), \(y_1\) horizontally according the value of each of the specified node’s children. The children are positioned in order, starting with the left edge (\(x_0\)) of the given rectangle. If the sum of the children’s values is less than the specified node’s value (i.e., if the specified node has a non-zero internal value), the remaining empty space will be positioned on the right edge (\(x_1\)) of the given rectangle.

Parameters:
  • parent (Node) – Parent node

  • x0 (float) – X-coordinate left edge

  • y0 (float) – Y-coordinate left edge

  • x1 (float) – X-coordinate right edge

  • y1 (float) – Y-coordinate right edge

detroit.treemap_resquarify(parent: Node, x0: float, y0: float, x1: float, y1: float)

Resquarify object

Parameters:

ratio (float) – Ratio value

detroit.treemap_slice(parent: Node, x0: float, y0: float, x1: float, y1: float)

Divides the rectangular area specified by \(x_0:, :math:`y_0\), \(x_1\), \(y_1\) vertically according the value of each of the specified node’s children. The children are positioned in order, starting with the top edge (\(y_0\)) of the given rectangle. If the sum of the children’s values is less than the specified node’s value (i.e., if the specified node has a non-zero internal value), the remaining empty space will be positioned on the bottom edge (\(y_1\)) of the given rectangle.

Parameters:
  • parent (Node) – Parent node

  • x0 (float) – X-coordinate top edge

  • y0 (float) – Y-coordinate top edge

  • x1 (float) – X-coordinate bottom edge

  • y1 (float) – Y-coordinate bottom edge

detroit.treemap_slice_dice(parent: Node, x0: float, y0: float, x1: float, y1: float)

If the specified parent has odd depth, delegates to d3.treemap_slice; otherwise delegates to d3.treemap_dice.

Parameters:
  • parent (Node) – Parent node

  • x0 (float) – X-coordinate rectangular edge

  • y0 (float) – Y-coordinate rectangular edge

  • x1 (float) – X-coordinate rectangular edge

  • y1 (float) – Y-coordinate rectangular edge

detroit.treemap_squarify(parent: Node, x0: float, y0: float, x1: float, y1: float)

Squarify object

Parameters:

ratio (float) – Ratio value

class detroit.hierarchy.treemap.resquarify.Resquarify(ratio: float)

Resquarify object

Parameters:

ratio (float) – Ratio value

__call__(parent: Node, x0: float, y0: float, x1: float, y1: float)

Like d3.treemap_resquarify, except preserves the topology (node adjacencies) of the previous layout computed by this function, if there is one and it used the same target aspect ratio. This tiling method is good for animating changes to treemaps because it only changes node sizes and not their relative positions, thus avoiding distracting shuffling and occlusion. The downside of a stable update, however, is a suboptimal layout for subsequent updates: only the first layout uses the Bruls et al. squarified algorithm.

Parameters:
  • parent (Node) – Parent node

  • x0 (float) – X-coordinate rectangular edge

  • y0 (float) – Y-coordinate rectangular edge

  • x1 (float) – X-coordinate rectangular edge

  • y1 (float) – Y-coordinate rectangular edge

set_ratio(ratio: float) Resquarify

Specifies the desired aspect ratio of the generated rectangles. The ratio must be specified as a number greater than or equal to one. Note that the orientation of the generated rectangles (tall or wide) is not implied by the ratio; for example, a ratio of two will attempt to produce a mixture of rectangles whose width:height ratio is either 2:1 or 1:2. (However, you can approximately achieve this result by generating a square treemap at different dimensions, and then stretching the treemap to the desired aspect ratio.) Furthermore, the specified ratio is merely a hint to the tiling algorithm; the rectangles are not guaranteed to have the specified aspect ratio. If not specified, the aspect ratio defaults to the golden ratio, \(\phi = (1 + \sqrt{5}) / 2\), per Kong et al<http://vis.stanford.edu/papers/perception-treemaps>_.

Parameters:

ratio (float) – Ratio value

Returns:

New Resquarify object

Return type:

Resquarify

class detroit.hierarchy.treemap.squarify.Squarify(ratio: float)

Squarify object

Parameters:

ratio (float) – Ratio value

__call__(parent: Node, x0: float, y0: float, x1: float, y1: float)

Implements the squarified treemap algorithm by Bruls et al., which seeks to produce rectangles of a given aspect ratio.

Parameters:
  • parent (Node) – Parent node

  • x0 (float) – X-coordinate rectangular edge

  • y0 (float) – Y-coordinate rectangular edge

  • x1 (float) – X-coordinate rectangular edge

  • y1 (float) – Y-coordinate rectangular edge

set_ratio(ratio: float) Squarify

Specifies the desired aspect ratio of the generated rectangles. The ratio must be specified as a number greater than or equal to one. Note that the orientation of the generated rectangles (tall or wide) is not implied by the ratio; for example, a ratio of two will attempt to produce a mixture of rectangles whose width:height ratio is either 2:1 or 1:2. (However, you can approximately achieve this result by generating a square treemap at different dimensions, and then stretching the treemap to the desired aspect ratio.) Furthermore, the specified ratio is merely a hint to the tiling algorithm; the rectangles are not guaranteed to have the specified aspect ratio. If not specified, the aspect ratio defaults to the golden ratio, \(\phi = (1 + \sqrt{5}) / 2\), per Kong et al<http://vis.stanford.edu/papers/perception-treemaps>_.

Parameters:

ratio (float) – Ratio value

Returns:

New Squarify object

Return type:

Squarify