Skip to content

Commit

Permalink
Disable color padding for cables with no multicolor wires
Browse files Browse the repository at this point in the history
  • Loading branch information
formatc1702 committed Jul 19, 2020
1 parent 3732597 commit 8cba793
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ def create_graph(self) -> Graph:

html = f'{html}<tr><td><table border="0" cellspacing="0" cellborder="0">' # conductor table

# determine if there are double- or triple-colored wires;
# if so, pad single-color wires to make all wires of equal thickness
colorlengths = list(map(len, cable.colors))
pad = 4 in colorlengths or 6 in colorlengths

for i, connection_color in enumerate(cable.colors, 1):
p = []
p.append(f'<!-- {i}_in -->')
Expand All @@ -204,7 +209,7 @@ def create_graph(self) -> Graph:
html = f'{html}<td>{bla}</td>'
html = f'{html}</tr>'

bgcolors = ['#000000'] + get_color_hex(connection_color) + ['#000000']
bgcolors = ['#000000'] + get_color_hex(connection_color, pad=pad) + ['#000000']
html = f'{html}<tr><td colspan="{len(p)}" border="0" cellspacing="0" cellpadding="0" port="w{i}" height="{(2 * len(bgcolors))}"><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
html = f'{html}<tr><td colspan="{len(p)}" cellpadding="0" height="2" bgcolor="{bgcolor if bgcolor != "" else wv_colors.default_color}" border="0"></td></tr>'
Expand Down Expand Up @@ -248,10 +253,10 @@ def create_graph(self) -> Graph:
# connections
for connection_color in cable.connections:
if isinstance(connection_color.via_port, int): # check if it's an actual wire and not a shield
dot.attr('edge', color=':'.join(['#000000'] + wv_colors.get_color_hex(cable.colors[connection_color.via_port - 1]) + ['#000000']))
dot.attr('edge', color=':'.join(['#000000'] + wv_colors.get_color_hex(cable.colors[connection_color.via_port - 1], pad=pad) + ['#000000']))
else: # it's a shield connection
# shield is shown as a thin tinned wire
dot.attr('edge', color=':'.join(['#000000', wv_colors.get_color_hex('SN')[0], '#000000']))
dot.attr('edge', color=':'.join(['#000000', wv_colors.get_color_hex('SN', pad=False)[0], '#000000']))
if connection_color.from_port is not None: # connect to left
from_ferrule = self.connectors[connection_color.from_name].category == 'ferrule'
port = f':p{connection_color.from_port}r' if not from_ferrule else ''
Expand Down
2 changes: 1 addition & 1 deletion src/wireviz/wv_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
color_default = '#ffffff'


def get_color_hex(input, pad=True):
def get_color_hex(input, pad=False):
if input is None or input == '':
return [color_default]
if len(input) == 4: # give wires with EXACTLY 2 colors that striped/banded look
Expand Down

0 comments on commit 8cba793

Please sign in to comment.