@@ -66,7 +66,7 @@ For **Tree** implementation, there are 9 main components.
66667 . [ ** 📊 Plotting Tree** ] ( https://bigtree.readthedocs.io/en/latest/bigtree/utils/plot.html )
6767 1 . Enhanced Reingold Tilford Algorithm to retrieve (x, y) coordinates for a tree structure
68688 . [ ** 🔨 Exporting Tree** ] ( https://bigtree.readthedocs.io/en/latest/bigtree/tree/export.html )
69- 1 . Print to console
69+ 1 . Print to console, in vertical or horizontal orientation
7070 2 . Export to * Newick string notation* , * dictionary* , * nested dictionary* , or * pandas DataFrame*
7171 3 . Export tree to * dot* (can save to .dot, .png, .svg, .jpeg files)
7272 4 . Export tree to * Pillow* (can save to .png, .jpg)
@@ -182,6 +182,11 @@ root.show()
182182# │ └── d
183183# └── c
184184
185+ root.hshow()
186+ # ┌─ b ─── d
187+ # ─ a ─┤
188+ # └─ c
189+
185190graph = tree_to_dot(root, node_colour = " gold" )
186191graph.write_png(" assets/docs/demo_tree.png" )
187192```
@@ -389,12 +394,13 @@ root.show(attr_list=["age"])
389394
390395### Print Tree
391396
392- After tree is constructed, it can be viewed by printing to console using ` show ` method directly.
393- Alternatively, the ` print_tree ` method can be used.
397+ After tree is constructed, it can be viewed by printing to console using ` show ` or ` hshow ` method directly,
398+ for vertical and horizontal orientation respectively.
399+ Alternatively, the ` print_tree ` or ` hprint_tree ` method can be used.
394400
395- {emphasize-lines="8,16,21 ,27,34,41,49,56,63,70,77,84,91-95 "}
401+ {emphasize-lines="8,15,22 ,27,33,40,47,55,62,69,76,83,90,97-101 "}
396402``` python
397- from bigtree import Node, print_tree
403+ from bigtree import Node, print_tree, hprint_tree
398404
399405root = Node(" a" , age = 90 , gender = " F" )
400406b = Node(" b" , age = 65 , gender = " M" , parent = root)
@@ -408,6 +414,12 @@ print_tree(root)
408414# │ └── e
409415# └── c
410416
417+ hprint_tree(root)
418+ # ┌─ d
419+ # ┌─ b ─┤
420+ # ─ a ─┤ └─ e
421+ # └─ c
422+
411423# Print subtree
412424print_tree(root, node_name_or_path = " b" )
413425# b
@@ -531,6 +543,7 @@ Below are the tables of attributes available to `BaseNode` and `Node` classes.
531543| Check if leaf node | ` root.is_leaf ` | False |
532544| Check depth of node | ` node_b.depth ` | 2 |
533545| Check depth of tree | ` node_b.max_depth ` | 4 |
546+ | Get root of tree | ` node_b.root ` | Node(/a, ) |
534547| Get node path | ` node_b.node_path ` | (Node(/a, ), Node(/a/b, )) |
535548| Get node name (only for ` Node ` ) | ` node_b.node_name ` | 'b' |
536549| Get node path name (only for ` Node ` ) | ` node_b.path_name ` | '/a/b' |
@@ -548,14 +561,18 @@ Below are the tables of attributes available to `BaseNode` and `Node` classes.
548561
549562Below is the table of operations available to ` BaseNode ` and ` Node ` classes.
550563
551- | Operations | Code | Returns |
552- | ------------------------------------| ------------------------------------------------------------| --------------------------------------------|
553- | Get node information | ` root.describe(exclude_prefix="_") ` | [ ('name', 'a')] |
554- | Find path from one node to another | ` root.go_to(node_e) ` | [ Node(/a, ), Node(/a/b, ), Node(/a/b/e, )] |
555- | Set attribute(s) | ` root.set_attrs({"description": "root-tag"}) ` | None |
556- | Get attribute | ` root.get_attr("description") ` | 'root-tag' |
557- | Copy tree | ` root.copy() ` | None |
558- | Sort children | ` root.sort(key=lambda node: node.node_name, reverse=True) ` | None |
564+ | Operations | Code | Returns |
565+ | -------------------------------------------------| ------------------------------------------------------------| --------------------------------------------|
566+ | Visualize tree (only for ` Node ` ) | ` root.show() ` | None |
567+ | Visualize tree (horizontally) (only for ` Node ` ) | ` root.hshow() ` | None |
568+ | Get node information | ` root.describe(exclude_prefix="_") ` | [ ('name', 'a')] |
569+ | Find path from one node to another | ` root.go_to(node_e) ` | [ Node(/a, ), Node(/a/b, ), Node(/a/b/e, )] |
570+ | Add child to node | ` root.append(Node("j")) ` | None |
571+ | Add multiple children to node | ` root.extend([Node("k"), Node("l")]) ` | None |
572+ | Set attribute(s) | ` root.set_attrs({"description": "root-tag"}) ` | None |
573+ | Get attribute | ` root.get_attr("description") ` | 'root-tag' |
574+ | Copy tree | ` root.copy() ` | None |
575+ | Sort children | ` root.sort(key=lambda node: node.node_name, reverse=True) ` | None |
559576
560577### Traverse Tree
561578
0 commit comments