Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added:
- Docs: Tips for setting custom coordinates for plots.
### Changed:
- Docs: Add more elaboration for exporting to image for tree and dag.
- Misc: Split tree/construct and tree/export into multiple files.

## [0.23.1] - 2025-01-22
Expand Down
31 changes: 31 additions & 0 deletions assets/tree_dag.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
strict digraph G {
graph [bb="0,0,126,252",
rankdir=TB
];
node [label="\N"];
c [height=0.5,
label=c,
pos="44,162",
width=0.75];
d [height=0.5,
label=d,
pos="71,90",
width=0.75];
c -> d [pos="e,64.524,107.79 50.536,144.05 53.521,136.32 57.131,126.96 60.483,118.27"];
a [height=0.5,
label=a,
pos="99,234",
width=0.75];
a -> c [pos="e,56.172,178.49 86.794,217.46 79.887,208.67 71.092,197.48 63.275,187.53"];
a -> d [pos="e,74.389,108.19 95.623,215.87 90.893,191.88 82.238,147.99 76.552,119.16"];
e [height=0.5,
label=e,
pos="71,18",
width=0.75];
d -> e [pos="e,71,36.104 71,71.697 71,64.407 71,55.726 71,47.536"];
b [height=0.5,
label=b,
pos="27,234",
width=0.75];
b -> c [pos="e,39.805,180.28 31.115,216.05 32.926,208.6 35.102,199.64 37.146,191.22"];
}
Binary file added assets/tree_dag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/tree_pillow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/tree_pillow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions bigtree/dag/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ def dag_to_dot(

Export to image, dot file, etc.

>>> dag_graph.write_png("assets/docstr/tree_dag.png")
>>> dag_graph.write_dot("assets/docstr/tree_dag.dot")
>>> dag_graph.write_png("assets/tree_dag.png")
>>> dag_graph.write_dot("assets/tree_dag.dot")

![Export to Dot](https://github.com/kayjan/bigtree/raw/master/assets/tree_dag.png)

Export to string

Expand Down
17 changes: 12 additions & 5 deletions bigtree/tree/export/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def tree_to_dot(
node_attr: Callable[[T], Dict[str, Any]] | str = "",
edge_attr: Callable[[T], Dict[str, Any]] | str = "",
) -> pydot.Dot:
r"""Export tree or list of trees to image.
r"""Export tree or list of trees to pydot.Dot object. Object can be
converted to other format, such as png, dot file or dot string. Dot
string can be imported to work with networkx.

Possible node attributes include style, fillcolor, shape.

Examples:
Expand Down Expand Up @@ -216,8 +219,10 @@ def tree_to_pillow(
bg_colour: Union[Tuple[int, int, int], str] = "white",
**kwargs: Any,
) -> Image.Image:
"""Export tree to image (JPG, PNG).
Image will be similar format as `print_tree`, accepts additional keyword arguments as input to `yield_tree`.
"""Export tree to PIL.Image.Image object. Object can be
converted to other format, such as jpg, or png. Image will be
similar format as `print_tree`, accepts additional keyword arguments
as input to `yield_tree`.

Examples:
>>> from bigtree import Node, tree_to_pillow
Expand All @@ -230,8 +235,10 @@ def tree_to_pillow(

Export to image (PNG, JPG) file, etc.

>>> pillow_image.save("assets/docstr/tree_pillow.png")
>>> pillow_image.save("assets/docstr/tree_pillow.jpg")
>>> pillow_image.save("assets/tree_pillow.png")
>>> pillow_image.save("assets/tree_pillow.jpg")

![Export to pillow](https://github.com/kayjan/bigtree/raw/master/assets/tree_pillow.png)

Args:
tree (Node): tree to be exported
Expand Down