|
|
@@ -1,8 +1,5 @@
|
|
|
# vim: set fileencoding=utf-8 :
|
|
|
# XXX Used in doctests (we should use them in the __main__ section below too).
|
|
|
-from node import Leaf, Node
|
|
|
-
|
|
|
-
|
|
|
def generate_graph(root, separator=' ', verbose=False):
|
|
|
"""
|
|
|
Return a text-based, utf-8 graph of a tree-like structure. Each tree node
|
|
|
@@ -10,6 +7,7 @@ def generate_graph(root, separator=' ', verbose=False):
|
|
|
``title``, that attribute will be called. That way, the node can return a
|
|
|
specific title, otherwise ``+`` is used.
|
|
|
|
|
|
+ >>> from node import Leaf, Node
|
|
|
>>> l0, l1 = Leaf(0), Leaf(1)
|
|
|
>>> n0 = Node('+', l0, l1)
|
|
|
>>> l2 = Leaf(2)
|
|
|
@@ -42,7 +40,7 @@ def generate_graph(root, separator=' ', verbose=False):
|
|
|
|
|
|
# Leaves do not have children and therefore the length of its title is
|
|
|
# the width of the leaf.
|
|
|
- if isinstance(node, Leaf):
|
|
|
+ if not node.nodes:
|
|
|
node_width[node] = title_len
|
|
|
node_middle[node] = int((title_len - 1) / 2)
|
|
|
return title_len
|
|
|
@@ -80,7 +78,7 @@ def generate_graph(root, separator=' ', verbose=False):
|
|
|
return width
|
|
|
|
|
|
def format_lines(node):
|
|
|
- if isinstance(node, Leaf):
|
|
|
+ if not node.nodes:
|
|
|
# Leaf titles do not need to be centered, since the parent will
|
|
|
# center those lines. And if there are no parents, the entire graph
|
|
|
# consists of a single leaf, so in that case there still is no
|