Skip to content

Commit

Permalink
text_viz.py: waterfall -> cascade.
Browse files Browse the repository at this point in the history
It is shorter, easier to remember for me, and the meaning
seems slightly more accurate.
  • Loading branch information
jordibc committed Feb 7, 2024
1 parent 0411587 commit 24197b7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions ete4/core/text_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@


def to_str(tree, show_internal=True, compact=False, props=None,
px=None, py=0, px0=0, waterfall=False):
px=None, py=0, px0=0, cascade=False):
"""Return a string containing an ascii drawing of the tree.
:param show_internal: If True, show the internal nodes too.
:param compact: If True, use exactly one line per tip.
:param props: List of node properties to show. If None, show all.
:param px, py, px0: Paddings (x, y, x for leaves). Overrides `compact`.
:param waterfall: Use a waterfall representation. Overrides
:param cascade: Use a cascade representation. Overrides
`show_internal`, `compact`, `px`, `py`, `px0`.
"""
if not waterfall:
if not cascade:
px = px if px is not None else (0 if show_internal else 1)
py = py if py is not None else (0 if compact else 1)

lines, _ = ascii_art(tree, show_internal, props, px, py, px0)
return '\n'.join(lines)
else:
px = px if px is not None else 1
return to_waterfall(tree, props, px)
return to_cascade(tree, props, px)


# For representations like:
Expand Down Expand Up @@ -133,8 +133,8 @@ def add_base(line, px, px0, txt, show_internal):
# │ └─╴d
# └─╴f

def to_waterfall(tree, props=None, px=1, are_last=None):
"""Return string with a visual representation of the tree as a waterfall."""
def to_cascade(tree, props=None, px=1, are_last=None):
"""Return string with a visual representation of the tree as a cascade."""
are_last = are_last or []

# Node description (including all the requested properties).
Expand All @@ -144,7 +144,7 @@ def to_waterfall(tree, props=None, px=1, are_last=None):

branches = get_branches_repr(are_last, tree.is_leaf, px)

wf = lambda n, lasts: to_waterfall(n, props, px, lasts) # shortcut
wf = lambda n, lasts: to_cascade(n, props, px, lasts) # shortcut

return '\n'.join([branches + descr] +
[wf(n, are_last + [False]) for n in tree.children[:-1]] +
Expand Down
6 changes: 3 additions & 3 deletions ete4/core/tree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,18 @@ cdef class Tree(object):
return self.to_str(show_internal=False, compact=True, props=['name'])

def to_str(self, show_internal=True, compact=False, props=None,
px=None, py=None, px0=0, waterfall=False):
px=None, py=None, px0=0, cascade=False):
"""Return a string containing an ascii drawing of the tree.
:param show_internal: If True, show the internal nodes too.
:param compact: If True, use exactly one line per tip.
:param props: List of node properties to show. If None, show all.
:param px, py, px0: Paddings (x, y, x for leaves). Overrides `compact`.
:param waterfall: Use a waterfall representation. Overrides
:param cascade: Use a cascade representation. Overrides
`show_internal`, `compact`, `px`, `py`, `px0`.
"""
return text_viz.to_str(self, show_internal, compact, props,
px, py, px0, waterfall)
px, py, px0, cascade)

def __contains__(self, item):
"""Return True if the tree contains the given item.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_to_str(self):
╰─┬╴c
╰╴d
"""))
self.assertEqual(t.to_str(props=['name'], waterfall=True), strip("""
self.assertEqual(t.to_str(props=['name'], cascade=True), strip("""
├─┐x
│ ├─╴a
Expand Down

0 comments on commit 24197b7

Please sign in to comment.