diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 4c93895..c46e157 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,14 +99,15 @@ 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 = [x.replace('>', colorbar) for x in html] if connector.style != 'simple': pinlist = [] + pinhtml = [] for pin, pinlabel in zip(connector.pins, connector.pinlabels): if connector.hide_disconnected_pins and not connector.visible_pins.get(pin, False): continue @@ -112,18 +115,20 @@ class Harness: f'{pinlabel}' if pinlabel else '', f'{pin}' if connector.ports_right else None]) - pinhtml = '' + pinhtml.append('
') for i, pin in enumerate(pinlist): - pinhtml = f'{pinhtml}' + pinhtml.append('') 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(f'{column}') + pinhtml.append('') + pinhtml.append('') + pinhtml = '\n'.join(pinhtml) + html = [x.replace('', pinhtml) for x in html] + html = '\n'.join(html) - dot.node(connector.name, label=f'<{html}>', shape='none', margin='0', style='filled', fillcolor='white') + 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 +151,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 +176,32 @@ 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 = [x.replace('>', colorbar) for x 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}' + wirehtml.append('') for cell in wirerow: - wirehtml = f'{wirehtml}' - wirehtml = f'{wirehtml}' + 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 +214,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}' + wirehtml.append('') # spacer + wirehtml.append('') for cell in wirerow: - wirehtml = wirehtml + f'' - wirehtml = f'{wirehtml}' + wirehtml.append(f'') + 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 +235,14 @@ 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}
{cell}
' + 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(f'' + wirehtml.append(f'') + wirehtml.append('
') + wirehtml.append('') for attrib in wireidentification: - wirehtml = f'{wirehtml}' - wirehtml = f'{wirehtml}
{attrib}
{attrib}
') + wirehtml.append('
 
 
{cell}
{cell}
 
' + wirehtml.append(' ') + wirehtml.append('') - html = html.replace('', wirehtml) + wirehtml = '\n'.join(wirehtml) + + html = [x.replace('', wirehtml) for x in html] # connections for connection_color in cable.connections: @@ -243,16 +257,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 = [x.replace(f'', from_string) for x 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 = [x.replace(f'', to_string) for x 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 b57634b..457c6e8 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(f'') + html.append(f'{row}') + html.append(f'') + html.append('') return html