Adding extra nicety attributes to nodes, and a sorting bugfix to ensure proper rendering.
This commit is contained in:
parent
d993a70ac7
commit
1dcdd10996
@ -4,7 +4,7 @@ from anytree.exporter import JsonExporter
|
||||
|
||||
def print_ingredients():
|
||||
for i, node in ingredients.items():
|
||||
print(f" {i}.) {node.name}")
|
||||
print(f" {i}.) {node.result}")
|
||||
|
||||
|
||||
ingredients = {}
|
||||
@ -17,7 +17,7 @@ while ingredient:
|
||||
ingredient = input("Add ingredient: ")
|
||||
|
||||
if ingredient:
|
||||
ingredients[i] = Node(ingredient)
|
||||
ingredients[i] = Node(ingredient, result=ingredient)
|
||||
i += 1
|
||||
|
||||
task = "start"
|
||||
@ -28,8 +28,10 @@ while task:
|
||||
|
||||
if task:
|
||||
needs = input("List needs (comma-separated): ")
|
||||
description = input("Detailed description: ")
|
||||
result = input("Result of task (e.g. chopped carrots): ")
|
||||
|
||||
new_task = Node(task)
|
||||
new_task = Node(task, description=description, result=result)
|
||||
|
||||
ingredients[i] = new_task
|
||||
i += 1
|
||||
|
@ -5,7 +5,7 @@ from sys import argv
|
||||
|
||||
def build_rows_depth_first(node, rows, leaf_count=0):
|
||||
|
||||
for child in sorted(node.children, key=lambda x: x.size, reverse=True):
|
||||
for child in sorted(node.children, key=lambda x: x.height, reverse=True):
|
||||
leaf_count = build_rows_depth_first(child, rows, leaf_count)
|
||||
|
||||
if node.is_leaf:
|
||||
@ -15,7 +15,7 @@ def build_rows_depth_first(node, rows, leaf_count=0):
|
||||
else:
|
||||
child_leaves = len(node.leaves)
|
||||
cur_row = leaf_count - child_leaves
|
||||
rows[cur_row].append(f'<td rowspan="{child_leaves}">{node.name}</td>')
|
||||
rows[cur_row].append(f'<td rowspan="{child_leaves}" title="{node.description}">{node.name}</td>')
|
||||
|
||||
return leaf_count
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user