From 8cba79334cb3bf689a9a3ace53fa2986bbe5abe7 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sat, 18 Jul 2020 12:50:16 +0200 Subject: [PATCH] Disable color padding for cables with no multicolor wires --- src/wireviz/Harness.py | 11 ++++++++--- src/wireviz/wv_colors.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 10ba4b8b..b989dce4 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -194,6 +194,11 @@ def create_graph(self) -> Graph: html = f'{html}' # 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'') @@ -204,7 +209,7 @@ def create_graph(self) -> Graph: html = f'{html}' html = f'{html}' - bgcolors = ['#000000'] + get_color_hex(connection_color) + ['#000000'] + bgcolors = ['#000000'] + get_color_hex(connection_color, pad=pad) + ['#000000'] html = f'{html}
{bla}
' for j, bgcolor in enumerate(bgcolors[::-1]): # Reverse to match the curved wires when more than 2 colors html = f'{html}' @@ -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 '' diff --git a/src/wireviz/wv_colors.py b/src/wireviz/wv_colors.py index 02316198..24e80b97 100644 --- a/src/wireviz/wv_colors.py +++ b/src/wireviz/wv_colors.py @@ -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