diff --git a/CHANGELOG.md b/CHANGELOG.md index 6780e3e9..f9d512fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.12.2] - 2023-09-12 +### Changed +- Tree Plot: Reingold Tilford Algorithm code for succinctness and docstring. + ## [0.12.1] - 2023-09-11 ### Fixed - Tree Plot: Reingold Tilford Algorithm to handle cases of negative x-coordinates with adjustment parameter. @@ -314,6 +318,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Utility Iterator: Tree traversal methods. - Workflow To Do App: Tree use case with to-do list implementation. +[0.12.2]: https://github.com/kayjan/bigtree/compare/0.12.1...0.12.2 [0.12.1]: https://github.com/kayjan/bigtree/compare/0.12.0...0.12.1 [0.12.0]: https://github.com/kayjan/bigtree/compare/0.11.0...0.12.0 [0.11.0]: https://github.com/kayjan/bigtree/compare/0.10.3...0.11.0 diff --git a/bigtree/__init__.py b/bigtree/__init__.py index 4d2cec33..c7145ccb 100644 --- a/bigtree/__init__.py +++ b/bigtree/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.12.1" +__version__ = "0.12.2" from bigtree.binarytree.construct import list_to_binarytree from bigtree.dag.construct import dataframe_to_dag, dict_to_dag, list_to_dag diff --git a/bigtree/utils/plot.py b/bigtree/utils/plot.py index 6d025c3d..9b5e5993 100644 --- a/bigtree/utils/plot.py +++ b/bigtree/utils/plot.py @@ -105,7 +105,7 @@ def first_pass( descendant of any left sibling at every subsequent level. Intersection happens when the subtrees are not at least `subtree distance` apart. - If there are any intersection, shift the whole subtree by a new `shift` value, shift any left sibling by a + If there are any intersections, shift the whole subtree by a new `shift` value, shift any left sibling by a fraction of `shift` value, and shift any right sibling by `shift` + a multiple of the fraction of `shift` value to keep nodes centralized at the level. @@ -166,25 +166,11 @@ def first_pass( ), ) - # Shift the nodes between leftmost subtree and right_node - for multiple, left_sibling in enumerate( - parent_node.children[:tree_node_idx] - ): - left_sibling.set_attrs( + # Shift siblings (left siblings, itself, right siblings) accordingly + for multiple, sibling in enumerate(parent_node.children): + sibling.set_attrs( { - "shift": left_sibling.get_attr("shift") - + (_shift * multiple / tree_node_idx) - } - ) - - # Shift right_node itself and the nodes to the right of right_node - for multiple, right_sibling in enumerate( - parent_node.children[tree_node_idx:] - ): - right_sibling.set_attrs( - { - "shift": right_sibling.get_attr("shift", 0) - + _shift + "shift": sibling.get_attr("shift", 0) + (_shift * multiple / tree_node_idx) } ) @@ -298,7 +284,7 @@ def second_pass( x_adjustment: Optional[float] = 0.0, ) -> float: """ - Performs pre-order traversal of tree and determine the final `x` and `y` values for each node. + Performs pre-order traversal of tree and determines the final `x` and `y` values for each node. Modifies tree in-place. Notation: @@ -352,7 +338,7 @@ def second_pass( def third_pass(tree_node: BaseNode, x_adjustment: float) -> None: - """Adjust all x-coordinates by an adjustment value so that every x-coordinate is greater than 0. + """Adjust all x-coordinates by an adjustment value so that every x-coordinate is greater than or equal to 0. Modifies tree in-place. Args: