From b5e3d0a4ce1d74ebd67ae4da865ab23f2830b64d Mon Sep 17 00:00:00 2001 From: KV Date: Sun, 28 Mar 2021 17:07:54 +0200 Subject: [PATCH] Add options bgcolor_connector, bgcolor_cable, and bgcolor_bundle --- src/wireviz/DataClasses.py | 13 +++++++++++++ src/wireviz/Harness.py | 9 ++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index 950cf23..e80437b 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -42,9 +42,22 @@ class Options: fontname: PlainText = 'arial' bgcolor: Color = 'WH' bgcolor_node: Optional[Color] = 'WH' + bgcolor_connector: Optional[Color] = None + bgcolor_cable: Optional[Color] = None + bgcolor_bundle: Optional[Color] = None color_mode: ColorMode = 'SHORT' mini_bom_mode: bool = True + def __post_init__(self): + if not self.bgcolor_node: + self.bgcolor_node = self.bgcolor + if not self.bgcolor_connector: + self.bgcolor_connector = self.bgcolor_node + if not self.bgcolor_cable: + self.bgcolor_cable = self.bgcolor_node + if not self.bgcolor_bundle: + self.bgcolor_bundle = self.bgcolor_cable + @dataclass class Image: diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 733b4aa..3918050 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -102,7 +102,7 @@ class Harness: shape='none', width='0', height='0', margin='0', # Actual size of the node is entirely determined by the label. style='filled', - fillcolor=wv_colors.translate_color(self.options.bgcolor_node or self.options.bgcolor, "HEX"), + fillcolor=wv_colors.translate_color(self.options.bgcolor_node, "HEX"), fontname=self.options.fontname) dot.attr('edge', style='bold', fontname=self.options.fontname) @@ -170,7 +170,8 @@ class Harness: html = [row.replace('', '\n'.join(pinhtml)) for row in html] html = '\n'.join(html) - dot.node(connector.name, label=f'<\n{html}\n>') + dot.node(connector.name, label=f'<\n{html}\n>', shape='box', style='filled', + fillcolor=translate_color(self.options.bgcolor_connector, "HEX")) if len(connector.loops) > 0: dot.attr('edge', color='#000000:#ffffff:#000000') @@ -337,9 +338,11 @@ class Harness: to_string = '' html = [row.replace(f'', to_string) for row in html] + style, bgcolor = ('filled,dashed', self.options.bgcolor_bundle) if cable.category == 'bundle' else \ + ('filled', self.options.bgcolor_cable) html = '\n'.join(html) dot.node(cable.name, label=f'<\n{html}\n>', shape='box', - style='filled,dashed' if cable.category == 'bundle' else 'filled') + style=style, fillcolor=translate_color(bgcolor, "HEX")) return dot