Remove obsolete nesting function, fine-tune table generating behavior

This commit is contained in:
Daniel Rojas 2020-07-05 21:45:39 +02:00
parent 7e54c7aaef
commit 6c7d700a1f
2 changed files with 2 additions and 17 deletions

View File

@ -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, \ from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, \
nested_html_table, flatten2d, index_if_list, html_line_breaks, \ nested_html_table, flatten2d, index_if_list, html_line_breaks, \
graphviz_line_breaks, remove_line_breaks graphviz_line_breaks, remove_line_breaks
from collections import Counter from collections import Counter
@ -91,7 +91,6 @@ class Harness:
f'MPN: {connector.manufacturer_part_number}' if connector.manufacturer_part_number else None, f'MPN: {connector.manufacturer_part_number}' if connector.manufacturer_part_number else None,
f'IPN: {connector.internal_part_number}' if connector.internal_part_number else None], f'IPN: {connector.internal_part_number}' if connector.internal_part_number else None],
[html_line_breaks(connector.notes)]] [html_line_breaks(connector.notes)]]
rows = [list(filter(None, row)) for row in rows] # remove missing attributes
html = nested_html_table(rows) html = nested_html_table(rows)
if connector.color: # add color bar next to color info, if present if connector.color: # add color bar next to color info, if present

View File

@ -30,20 +30,6 @@ def awg_equiv(mm2):
def mm2_equiv(awg): def mm2_equiv(awg):
return mm2_equiv_table.get(str(awg), 'Unknown') return mm2_equiv_table.get(str(awg), 'Unknown')
def nested(inp):
l = []
for x in inp:
if isinstance(x, list):
if len(x) > 0:
n = nested(x)
if n != '':
l.append('{' + n + '}')
else:
if x is not None:
if x != '':
l.append(str(x))
return '|'.join(l)
def nested_html_table(rows): def nested_html_table(rows):
# input: list, each item may be scalar or list # input: list, each item may be scalar or list
# output: a parent table with one child table per parent item that is list, and one cell per parent item that is scalar # output: a parent table with one child table per parent item that is list, and one cell per parent item that is scalar
@ -57,7 +43,7 @@ def nested_html_table(rows):
if cell is not None: if cell is not None:
html = f'{html}<td balign="left">{cell}</td>' html = f'{html}<td balign="left">{cell}</td>'
html = f'{html}</tr></table></td></tr>' html = f'{html}</tr></table></td></tr>'
else: elif row is not None:
html = f'{html}<tr><td>{row}</td></tr>' html = f'{html}<tr><td>{row}</td></tr>'
html = f'{html}</table>' html = f'{html}</table>'
return html return html