Table layout improvements.
This commit is contained in:
parent
be959f6664
commit
ba6d5f4255
@ -8,14 +8,26 @@ def build_rows_depth_first(node, rows, leaf_count=0):
|
|||||||
for child in sorted(node.children, key=lambda x: x.height, 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)
|
leaf_count = build_rows_depth_first(child, rows, leaf_count)
|
||||||
|
|
||||||
|
colspan = 0
|
||||||
|
if node.siblings:
|
||||||
|
max_sibling_height = max([s.height for s in node.siblings])
|
||||||
|
|
||||||
|
if max_sibling_height > node.height:
|
||||||
|
colspan = max_sibling_height - node.height + 1
|
||||||
|
|
||||||
if node.is_leaf:
|
if node.is_leaf:
|
||||||
cur_row = leaf_count
|
cur_row = leaf_count
|
||||||
rows[cur_row].append(f'<td>{node.name}</td>')
|
rows[cur_row].append(f'<th>{node.name}</th>')
|
||||||
|
|
||||||
|
if colspan > 1:
|
||||||
|
rows[cur_row].append(f'<td colspan="{colspan-1}"></td>')
|
||||||
|
|
||||||
leaf_count += 1
|
leaf_count += 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
child_leaves = len(node.leaves)
|
child_leaves = len(node.leaves)
|
||||||
cur_row = leaf_count - child_leaves
|
cur_row = leaf_count - child_leaves
|
||||||
rows[cur_row].append(f'<td rowspan="{child_leaves}" title="{node.description}">{node.name}</td>')
|
rows[cur_row].append(f"<td rowspan='{child_leaves}' colspan='{colspan}' title='{node.description}'>{node.name}</td>")
|
||||||
|
|
||||||
return leaf_count
|
return leaf_count
|
||||||
|
|
||||||
@ -34,8 +46,12 @@ for i in range(len(root.leaves)):
|
|||||||
|
|
||||||
build_rows_depth_first(root, output_rows)
|
build_rows_depth_first(root, output_rows)
|
||||||
|
|
||||||
|
print("<table cellspacing='0'>")
|
||||||
|
|
||||||
for row in output_rows:
|
for row in output_rows:
|
||||||
print("<tr>")
|
print("<tr>")
|
||||||
for cell in row:
|
for cell in row:
|
||||||
print(f" {cell}")
|
print(f" {cell}")
|
||||||
print("</tr>")
|
print("</tr>")
|
||||||
|
|
||||||
|
print("</table>")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user