diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 4c93895..635fae9 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -88,6 +88,8 @@ class Harness: for connector in self.connectors.values(): + html = [] + rows = [[connector.name if connector.show_name else None], [f'P/N: {connector.pn}' if connector.pn else None, html_line_breaks(manufacturer_info_field(connector.manufacturer, connector.mpn))], @@ -97,33 +99,34 @@ class Harness: connector.color, '' if connector.color else None], '' if connector.style != 'simple' else None, [html_line_breaks(connector.notes)]] - html = nested_html_table(rows) + html.extend(nested_html_table(rows)) if connector.color: # add color bar next to color info, if present colorbar = f' bgcolor="{wv_colors.translate_color(connector.color, "HEX")}" width="4">' # leave out ' tag - html = html.replace('>', colorbar) + html = [row.replace('>', colorbar) for row in html] if connector.style != 'simple': - pinlist = [] + pinhtml = [] + pinhtml.append('') + for pin, pinlabel in zip(connector.pins, connector.pinlabels): if connector.hide_disconnected_pins and not connector.visible_pins.get(pin, False): continue - pinlist.append([f'' if connector.ports_left else None, - f'' if pinlabel else '', - f'' if connector.ports_right else None]) + pinhtml.append('') + if connector.ports_left: + pinhtml.append(f'') + if pinlabel: + pinhtml.append(f'') + if connector.ports_right: + pinhtml.append(f'') + pinhtml.append('') - pinhtml = '
{pin}{pinlabel}{pin}
{pin}{pinlabel}{pin}
' - for i, pin in enumerate(pinlist): - pinhtml = f'{pinhtml}' - for column in pin: - if column is not None: - pinhtml = f'{pinhtml}{column}' - pinhtml = f'{pinhtml}' - pinhtml = f'{pinhtml}
' - html = html.replace('', pinhtml) + pinhtml.append('') + html = [row.replace('', '\n'.join(pinhtml)) for row in html] - dot.node(connector.name, label=f'<{html}>', shape='none', margin='0', style='filled', fillcolor='white') + html = '\n'.join(html) + dot.node(connector.name, label=f'<\n{html}\n>', shape='none', margin='0', style='filled', fillcolor='white') if len(connector.loops) > 0: dot.attr('edge', color='#000000:#ffffff:#000000') @@ -146,6 +149,8 @@ class Harness: for cable in self.cables.values(): + html = [] + awg_fmt = '' if cable.show_equiv: # Only convert units we actually know about, i.e. currently @@ -169,29 +174,30 @@ class Harness: cable.color, '' if cable.color else None], '', [html_line_breaks(cable.notes)]] - html = nested_html_table(rows) + html.extend(nested_html_table(rows)) if cable.color: # add color bar next to color info, if present colorbar = f' bgcolor="{wv_colors.translate_color(cable.color, "HEX")}" width="4">' # leave out ' tag - html = html.replace('>', colorbar) + html = [row.replace('>', colorbar) for row in html] - wirehtml = '' # conductor table - wirehtml = f'{wirehtml}' + wirehtml = [] + wirehtml.append('
 
') # conductor table + wirehtml.append('') for i, connection_color in enumerate(cable.colors, 1): - wirerow = [f'', - wv_colors.translate_color(connection_color, self.color_mode), - f''] - wirehtml = f'{wirehtml}' - for cell in wirerow: - wirehtml = f'{wirehtml}' - wirehtml = f'{wirehtml}' + wirehtml.append('') + wirehtml.append(f'') + wirehtml.append(f'') + wirehtml.append(f'') + wirehtml.append('') bgcolors = ['#000000'] + get_color_hex(connection_color, pad=pad) + ['#000000'] - wirehtml = f'{wirehtml}') if(cable.category == 'bundle'): # for bundles individual wires can have part information # create a list of wire parameters wireidentification = [] @@ -204,18 +210,20 @@ class Harness: wireidentification.append(html_line_breaks(manufacturer_info)) # print parameters into a table row under the wire if(len(wireidentification) > 0): - wirehtml = f'{wirehtml}') if cable.shield: - wirerow = ['', 'Shield', ''] - wirehtml = f'{wirehtml}' # spacer - wirehtml = f'{wirehtml}' - for cell in wirerow: - wirehtml = wirehtml + f'' - wirehtml = f'{wirehtml}' + wirehtml.append('') # spacer + wirehtml.append('') + wirehtml.append('') + wirehtml.append('') + wirehtml.append('') + wirehtml.append('') if isinstance(cable.shield, str): # shield is shown with specified color and black borders shield_color_hex = wv_colors.get_color_hex(cable.shield)[0] @@ -223,12 +231,12 @@ class Harness: else: # shield is shown as a thin black wire attributes = f'height="2" bgcolor="#000000" border="0"' - wirehtml = f'{wirehtml}' + wirehtml.append(f'') - wirehtml = f'{wirehtml}' - wirehtml = f'{wirehtml}
 
{cell}
{wv_colors.translate_color(connection_color, self.color_mode)}
' + wirehtml.append(f'' + wirehtml.append(f'') + wirehtml.append('
') + wirehtml.append('') for j, bgcolor in enumerate(bgcolors[::-1]): # Reverse to match the curved wires when more than 2 colors - wirehtml = f'{wirehtml}' - wirehtml = wirehtml + '
') + wirehtml.append('
' + wirehtml.append('' + wirehtml.append(f'') + wirehtml.append('
') + wirehtml.append('') for attrib in wireidentification: - wirehtml = f'{wirehtml}' - wirehtml = f'{wirehtml}
{attrib}
{attrib}
') + wirehtml.append('
 
{cell}
 
Shield
 
' + wirehtml.append(' ') + wirehtml.append('') - html = html.replace('', wirehtml) + html = [row.replace('', '\n'.join(wirehtml)) for row in html] # connections for connection_color in cable.connections: @@ -243,16 +251,17 @@ class Harness: code_left_2 = f'{cable.name}:w{connection_color.via_port}:w' dot.edge(code_left_1, code_left_2) from_string = f'{connection_color.from_name}:{connection_color.from_port}' if self.connectors[connection_color.from_name].show_name else '' - html = html.replace(f'', from_string) + html = [row.replace(f'', from_string) for row in html] if connection_color.to_port is not None: # connect to right code_right_1 = f'{cable.name}:w{connection_color.via_port}:e' to_port = f':p{connection_color.to_port}l' if self.connectors[connection_color.to_name].style != 'simple' else '' code_right_2 = f'{connection_color.to_name}{to_port}:w' dot.edge(code_right_1, code_right_2) to_string = f'{connection_color.to_name}:{connection_color.to_port}' if self.connectors[connection_color.to_name].show_name else '' - html = html.replace(f'', to_string) + html = [row.replace(f'', to_string) for row in html] - dot.node(cable.name, label=f'<{html}>', shape='box', + html = '\n'.join(html) + dot.node(cable.name, label=f'<\n{html}\n>', shape='box', style='filled,dashed' if cable.category == 'bundle' else '', margin='0', fillcolor='white') return dot diff --git a/src/wireviz/wv_helper.py b/src/wireviz/wv_helper.py index ae3a07c..e42dc96 100644 --- a/src/wireviz/wv_helper.py +++ b/src/wireviz/wv_helper.py @@ -34,18 +34,23 @@ def nested_html_table(rows): # 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 # purpose: create the appearance of one table, where cell widths are independent between rows - html = '' + html = [] + html.append('
') for row in rows: if isinstance(row, List): if len(row) > 0 and any(row): - html = f'{html}') elif row is not None: - html = f'{html}' - html = f'{html}
' + html.append('' + html.append(f'') + html.append('
') + html.append('') for cell in row: if cell is not None: - html = f'{html}' - html = f'{html}
{cell}
{cell}
') + html.append('
{row}
' + html.append('') + html.append(row) + html.append('') + html.append('') return html