Treemap¶
- detroit.treemap() TreeMap¶
Builds a new treemap layout with default settings.
- Returns:
TreeMap object
- Return type:
- 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 rectanglenode.y0- the top edge of the rectanglenode.x1- the right edge of the rectanglenode.y1- the bottom edge of the rectangle
You must call
root.sumbefore passing the hierarchy to the treemap layout. You probably also want to call root.sort to order the hierarchy before computing the layout.
- 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:
- set_round(round_value: bool) TreeMap¶
If
roundis 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:
- set_size(size: tuple[float, float]) TreeMap¶
If
sizeis 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:
- 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.
- 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_inneris 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.
- 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.
- 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_topis 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.
- 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_rightis 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.
- 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_bottomis 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.
- 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_leftis 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.
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
parenthas odd depth, delegates tod3.treemap_slice; otherwise delegates tod3.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:1or1: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:
- 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:1or1: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: