Skip to content

Commit

Permalink
Improve rendering of cable node
Browse files Browse the repository at this point in the history
Display wire number, color and label, as needed
  • Loading branch information
formatc1702 committed Nov 14, 2020
1 parent 89562b1 commit 1578855
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,31 @@ def create_graph(self) -> Graph:
wirehtml.append('<table border="0" cellspacing="0" cellborder="0">') # conductor table
wirehtml.append(' <tr><td>&nbsp;</td></tr>')

colspan = 4 if cable.wirelabels else 3

for i, (connection_color, wirelabel) in enumerate(zip_longest(cable.colors, cable.wirelabels), 1):
wirehtml.append(' <tr>')
wirehtml.append(f' <td><!-- {i}_in --></td>')
wirehtml.append(f' <td>{wv_colors.translate_color(connection_color, self.color_mode)}</td>')
wirehtml.append(f' <td>')

wireinfo = []
if cable.show_wirenumbers:
wireinfo.append(str(i))
colorstr = wv_colors.translate_color(connection_color, self.color_mode)
if colorstr:
wireinfo.append(colorstr)
if cable.wirelabels:
wirehtml.append(f' <td>[{wirelabel}]</td>')
wireinfo.append(wirelabel if wirelabel else '')
wirehtml.append(f' {":".join(wireinfo)}')

wirehtml.append(f' </td>')
wirehtml.append(f' <td><!-- {i}_out --></td>')
wirehtml.append(' </tr>')

bgcolors = ['#000000'] + get_color_hex(connection_color, pad=pad) + ['#000000']
wirehtml.append(f' <tr>')
wirehtml.append(f' <td colspan="{colspan}" border="0" cellspacing="0" cellpadding="0" port="w{i}" height="{(2 * len(bgcolors))}">')
wirehtml.append(f' <td colspan="3" border="0" cellspacing="0" cellpadding="0" port="w{i}" height="{(2 * len(bgcolors))}">')
wirehtml.append(' <table cellspacing="0" cellborder="0" border="0">')
for j, bgcolor in enumerate(bgcolors[::-1]): # Reverse to match the curved wires when more than 2 colors
wirehtml.append(f' <tr><td colspan="{colspan}" cellpadding="0" height="2" bgcolor="{bgcolor if bgcolor != "" else wv_colors.default_color}" border="0"></td></tr>')
wirehtml.append(f' <tr><td colspan="3" cellpadding="0" height="2" bgcolor="{bgcolor if bgcolor != "" else wv_colors.default_color}" border="0"></td></tr>')
wirehtml.append(' </table>')
wirehtml.append(' </td>')
wirehtml.append(' </tr>')
Expand All @@ -245,7 +253,7 @@ def create_graph(self) -> Graph:
wireidentification.append(html_line_breaks(manufacturer_info))
# print parameters into a table row under the wire
if len(wireidentification) > 0 :
wirehtml.append(' <tr><td colspan="{colspan}">')
wirehtml.append(' <tr><td colspan="3">')
wirehtml.append(' <table border="0" cellspacing="0" cellborder="0"><tr>')
for attrib in wireidentification:
wirehtml.append(f' <td>{attrib}</td>')
Expand All @@ -266,7 +274,7 @@ def create_graph(self) -> Graph:
else:
# shield is shown as a thin black wire
attributes = f'height="2" bgcolor="#000000" border="0"'
wirehtml.append(f' <tr><td colspan="{colspan}" cellpadding="0" {attributes} port="ws"></td></tr>')
wirehtml.append(f' <tr><td colspan="3" cellpadding="0" {attributes} port="ws"></td></tr>')

wirehtml.append(' <tr><td>&nbsp;</td></tr>')
wirehtml.append(' </table>')
Expand Down

0 comments on commit 1578855

Please sign in to comment.