Pack

detroit.pack() Pack
detroit.pack_enclose(circles: list[dict[str, float]]) Circle

Computes the smallest circle that encloses the specified array of circles, each of which must have a circle.r property specifying the circle’s radius, and circle.x and circle.y properties specifying the circle’s center. The enclosing circle is computed using the Matoušek-Sharir-Welzl algorithm. (See also Apollonius’ Problem.)

Parameters:

circles (list[dict[str, float]]) – List of circles defined as dictionaries such as circle = {"x": ..., "y": ..., "r": ...}

Returns:

Smallest circle that enclosed the specified array of circles

Return type:

Circle

detroit.pack_siblings(circles: list[Circle]) list[Circle]

Packs the specified array of circles, each of which must have a circle.r property specifying the circle’s radius. Assigns the following properties to each circle:

  • circle.x - the x-coordinate of the circle’s center

  • circle.y - the y coordinate of the circle’s center

The circles are positioned according to the front-chain packing algorithm by Wang et al.

Parameters:

circles (list[Circle]) – List of circles

Returns:

Packed list of circles

Return type:

list[Circle]

class detroit.hierarchy.pack.pack.Pack

Pack 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 circle’s center

  • node.y - the y coordinate of the circle’s center

  • node.r - the radius of the circle

You must call root.sum before passing the hierarchy to the pack 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 pack

Return type:

Node

set_radius(radius: Callable[[Node], float] | None) Pack

Sets the pack layout’s radius accessor to the specified function and returns this pack layout. If radius is not specified, returns the current radius accessor, which defaults to None. If the radius accessor is None, the radius of each leaf circle is derived from the leaf node.value (computed by node.sum); the radii are then scaled proportionally to fit the layout size. If the radius accessor is not None, the radius of each leaf circle is specified exactly by the function.

Parameters:

radius (Callable[[Node], float] | None) – Radius function or None value

Returns:

Itself

Return type:

Pack

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

Sets this pack layout’s size to the specified two-element array of numbers [width, height] and returns this pack layout.

Parameters:

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

Returns:

Itself

Return type:

Pack

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

If padding is specified, sets this pack layout’s padding accessor to the specified number or function and returns this pack layout. When siblings are packed, tangent siblings will be separated by approximately the specified padding; the enclosing parent circle will also be separated from its children by approximately the specified padding. If an explicit radius is not specified, the padding is approximate because a two-pass algorithm is needed to fit within the layout size: the circles are first packed without padding; a scaling factor is computed and applied to the specified padding; and lastly the circles are re-packed with padding.

Parameters:

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

Returns:

Itself

Return type:

Pack