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.rproperty specifying the circle’s radius, andcircle.xandcircle.yproperties 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.rproperty specifying the circle’s radius. Assigns the following properties to each circle:circle.x- the x-coordinate of the circle’s centercircle.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 centernode.y- the y coordinate of the circle’s centernode.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.
- 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
radiusis not specified, returns the current radius accessor, which defaults toNone. If the radius accessor isNone, the radius of each leaf circle is derived from the leafnode.value(computed bynode.sum); the radii are then scaled proportionally to fit the layout size. If theradiusaccessor is notNone, the radius of each leaf circle is specified exactly by the function.
- 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:
- set_padding(padding: Callable[[Node], float] | float) Pack¶
If
paddingis 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.