From 28a3e1d460f9363f730f4dc36031d6e99b40ecbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Br=C3=BCckner?= Date: Wed, 22 Jul 2020 13:25:32 +0200 Subject: [PATCH 1/3] split edge color in multiple edges --- src/wireviz/Harness.py | 43 ++++++++++++++++++++++++++++++++++------ src/wireviz/wv_colors.py | 8 ++++---- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index a3aa0ce2..25ef770b 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -246,25 +246,56 @@ 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], pad=pad) + ['#000000'])) + colors = wv_colors.get_color_hex(cable.colors[connection_color.via_port - 1]) + isShield=False + #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', pad=False)[0], '#000000'])) - if connection_color.from_port is not None: # connect to left + colors = wv_colors.get_color_hex('SN', pad=False) + isShield=True + #dot.attr('edge', color=':'.join(['#000000', wv_colors.get_color_hex('SN', pad=False)[0], '#000000'])) + + + leftConn = connection_color.from_port is not None + rightConn = connection_color.to_port is not None + + + if leftConn: # connect to left from_port = f':p{connection_color.from_port}r' if self.connectors[connection_color.from_name].style != 'simple' else '' code_left_1 = f'{connection_color.from_name}{from_port}:e' 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) - if connection_color.to_port is not None: # connect to right + + if rightConn: # 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) + #black cable borders + if not isShield: + dot.attr('edge', style="solid", penwidth="6.0", color='#000000') + if leftConn: + dot.edge(code_left_1, code_left_2) + if rightConn: + dot.edge(code_right_1, code_right_2) + + #invis cable to break graphviz edge ordering + dot.attr('edge', style='invis') + if leftConn: + dot.edge (connection_color.from_name, cable.name) + if rightConn: + dot.edge (cable.name, connection_color.to_name) + + #cable color + dot.attr('edge', style="solid", penwidth="2.0", color=colors[0]) + if leftConn: + dot.edge(code_left_1, code_left_2) + if rightConn: + dot.edge(code_right_1, code_right_2) + dot.node(cable.name, label=f'<{html}>', shape='box', style='filled,dashed' if cable.category == 'bundle' else '', margin='0', fillcolor='white') diff --git a/src/wireviz/wv_colors.py b/src/wireviz/wv_colors.py index 41575437..f5c47c05 100644 --- a/src/wireviz/wv_colors.py +++ b/src/wireviz/wv_colors.py @@ -104,11 +104,11 @@ 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 - input = input + input[:2] + #if len(input) == 4: # give wires with EXACTLY 2 colors that striped/banded look + # input = input + input[:2] # hacky style fix: give single color wires a triple-up so that wires are the same size - if pad and len(input) == 2: - input = input + input + input + #if pad and len(input) == 2: + # input = input + input + input try: output = [_color_hex[input[i:i + 2]] for i in range(0, len(input), 2)] except KeyError: From 4c1f92ea80963388d81658a2c2860130ffc67cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Br=C3=BCckner?= Date: Wed, 22 Jul 2020 13:38:40 +0200 Subject: [PATCH 2/3] add 2nd color as dashed overlay --- src/wireviz/Harness.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 25ef770b..4928653a 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -296,6 +296,20 @@ def create_graph(self) -> Graph: if rightConn: dot.edge(code_right_1, code_right_2) + if len(colors) > 1: + #invis cable to break graphviz edge ordering + dot.attr('edge', style='invis') + if leftConn: + dot.edge (connection_color.from_name, cable.name) + if rightConn: + dot.edge (cable.name, connection_color.to_name) + + dot.attr('edge', style="dashed", penwidth="2.0", color=colors[1]) + if leftConn: + dot.edge(code_left_1, code_left_2) + if rightConn: + dot.edge(code_right_1, code_right_2) + dot.node(cable.name, label=f'<{html}>', shape='box', style='filled,dashed' if cable.category == 'bundle' else '', margin='0', fillcolor='white') From 9881ed6e7b34f339c362016152e9f024211acd07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Br=C3=BCckner?= Date: Wed, 22 Jul 2020 14:59:00 +0200 Subject: [PATCH 3/3] show banded color in table (hard coded to 12 bands) --- src/wireviz/Harness.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 4928653a..4c2bf756 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -202,11 +202,18 @@ def create_graph(self) -> Graph: html = f'{html}{bla}' html = f'{html}' - bgcolors = ['#000000'] + get_color_hex(connection_color, pad=pad) + ['#000000'] - html = f'{html}' - for j, bgcolor in enumerate(bgcolors[::-1]): # Reverse to match the curved wires when more than 2 colors - html = f'{html}' - html = html + '
' + colors = get_color_hex(connection_color) + html = f'{html}' + html = f'{html}' + numColors = len(colors) + for i in range(12) if numColors > 1 else range(1): #12 works well up to 4 colors + html = f'{html}' + + html = html + '
' + + #for j, bgcolor in enumerate(bgcolors[::-1]): # Reverse to match the curved wires when more than 2 colors + # html = f'{html}' + #html = html + '' if(cable.category == 'bundle'): # for bundles individual wires can have part information # create a list of wire parameters wireidentification = [] @@ -290,7 +297,7 @@ def create_graph(self) -> Graph: dot.edge (cable.name, connection_color.to_name) #cable color - dot.attr('edge', style="solid", penwidth="2.0", color=colors[0]) + dot.attr('edge', style="solid", penwidth="4.0" if isShield else "2.0", color=colors[0]) if leftConn: dot.edge(code_left_1, code_left_2) if rightConn: