Outsource nested HTML table creation to helper function
This commit is contained in:
parent
0252476248
commit
e1e665583f
@ -4,7 +4,7 @@
|
|||||||
from wireviz.DataClasses import Connector, Cable
|
from wireviz.DataClasses import Connector, Cable
|
||||||
from graphviz import Graph
|
from graphviz import Graph
|
||||||
from wireviz import wv_colors
|
from wireviz import wv_colors
|
||||||
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, nested, flatten2d, index_if_list, html_line_breaks, graphviz_line_breaks, remove_line_breaks
|
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, nested, nested_html_table, flatten2d, index_if_list, html_line_breaks, graphviz_line_breaks, remove_line_breaks
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
@ -67,14 +67,7 @@ class Harness:
|
|||||||
[html_line_breaks(connector.notes)]]
|
[html_line_breaks(connector.notes)]]
|
||||||
rows = [list(filter(None, row)) for row in rows] # remove missing attributes
|
rows = [list(filter(None, row)) for row in rows] # remove missing attributes
|
||||||
|
|
||||||
html = '<table border="0" cellspacing="0" cellpadding="0">'
|
html = nested_html_table(rows)
|
||||||
for row in rows:
|
|
||||||
if len(row) > 0:
|
|
||||||
html = f'{html}<tr><td><table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>'
|
|
||||||
for cell in row:
|
|
||||||
html = f'{html}<td balign="left">{cell}</td>'
|
|
||||||
html = f'{html}</tr></table></td></tr>'
|
|
||||||
html = f'{html}</table>'
|
|
||||||
|
|
||||||
if connector.color: # add color bar next to color info, if present
|
if connector.color: # add color bar next to color info, if present
|
||||||
colorbar = f' bgcolor="{wv_colors.translate_color(connector.color, "HEX")}" width="4"></td>' # leave out '<td' from string to preserve any existing attributes of the <td> tag
|
colorbar = f' bgcolor="{wv_colors.translate_color(connector.color, "HEX")}" width="4"></td>' # leave out '<td' from string to preserve any existing attributes of the <td> tag
|
||||||
|
|||||||
@ -44,6 +44,20 @@ def nested(inp):
|
|||||||
l.append(str(x))
|
l.append(str(x))
|
||||||
return '|'.join(l)
|
return '|'.join(l)
|
||||||
|
|
||||||
|
def nested_html_table(rows):
|
||||||
|
# input: list of lists
|
||||||
|
# output: a parent table with one child table per parent list item
|
||||||
|
# purpose: create the appearance of one table, where cell widths are independent between rows
|
||||||
|
html = '<table border="0" cellspacing="0" cellpadding="0">'
|
||||||
|
for row in rows:
|
||||||
|
if len(row) > 0:
|
||||||
|
html = f'{html}<tr><td><table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>'
|
||||||
|
for cell in row:
|
||||||
|
html = f'{html}<td balign="left">{cell}</td>'
|
||||||
|
html = f'{html}</tr></table></td></tr>'
|
||||||
|
html = f'{html}</table>'
|
||||||
|
return html
|
||||||
|
|
||||||
|
|
||||||
def int2tuple(inp):
|
def int2tuple(inp):
|
||||||
if isinstance(inp, tuple):
|
if isinstance(inp, tuple):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user