From c219b156e819657b68c806a2d795075856094b25 Mon Sep 17 00:00:00 2001 From: Alasdair Gray Date: Wed, 17 May 2023 13:27:13 -0400 Subject: [PATCH] Change logic for auto-fading connections (#53) * Add ability to specify additional latex packages * Change logic for auto fading connections * Update auto-fade docstring * Fade horizontal and vertical connection edges based on src/target fading * Bump version * Fixing minor version --------- Co-authored-by: Andrew Lamkin --- pyxdsm/XDSM.py | 22 +++++++++++++--------- pyxdsm/__init__.py | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pyxdsm/XDSM.py b/pyxdsm/XDSM.py index f60736c..cd3a1cc 100644 --- a/pyxdsm/XDSM.py +++ b/pyxdsm/XDSM.py @@ -113,7 +113,7 @@ def _label_to_spec(label, spec): System = namedtuple("System", "node_name style label stack faded label_width spec_name") Input = namedtuple("Input", "node_name label label_width style stack faded") Output = namedtuple("Output", "node_name label label_width style stack faded side") -Connection = namedtuple("Connection", "src target label label_width style stack faded") +Connection = namedtuple("Connection", "src target label label_width style stack faded src_faded target_faded") Process = namedtuple("Process", "systems arrow faded") @@ -130,7 +130,7 @@ def __init__(self, use_sfmath=True, optional_latex_packages=None, auto_fade=None auto_fade : dictionary, optional Controls the automatic fading of inputs, outputs, connections and processes based on the fading of diagonal blocks. For each key "inputs", "outputs", "connections", and "processes", the value can be one of: - "all" : fade all blocks - - "connected" : fade all components connected to faded blocks + - "connected" : fade all components connected to faded blocks (both source and target must be faded for a conncection to be faded) - "none" : do not auto-fade anything For connections there are two additional options: - "incoming" : Fade all connections that are incoming to faded blocks. @@ -376,13 +376,13 @@ def connect( targetFaded = target in sys_faded and sys_faded[target] if ( allFaded - or (self.auto_fade["connections"] == "connected" and (srcFaded or targetFaded)) + or (self.auto_fade["connections"] == "connected" and (srcFaded and targetFaded)) or (self.auto_fade["connections"] == "incoming" and targetFaded) or (self.auto_fade["connections"] == "outgoing" and srcFaded) ): faded = True - self.connections.append(Connection(src, target, label, label_width, style, stack, faded)) + self.connections.append(Connection(src, target, label, label_width, style, stack, faded, srcFaded, targetFaded)) def add_process(self, systems, arrow=True, faded=False): """ @@ -536,12 +536,16 @@ def _build_edges(self): edge_format_string = "({start}) edge [{style}] ({end})" for conn in self.connections: - style = "DataLine" - if conn.faded: - style += ",faded" + h_edge_style = "DataLine" + v_edge_style = "DataLine" + if conn.src_faded or conn.faded: + h_edge_style += ",faded" + if conn.target_faded or conn.faded: + v_edge_style += ",faded" od_node_name = "{}-{}".format(conn.src, conn.target) - h_edges.append(edge_format_string.format(start=conn.src, end=od_node_name, style=style)) - v_edges.append(edge_format_string.format(start=od_node_name, end=conn.target, style=style)) + + h_edges.append(edge_format_string.format(start=conn.src, end=od_node_name, style=h_edge_style)) + v_edges.append(edge_format_string.format(start=od_node_name, end=conn.target, style=v_edge_style)) for comp_name, out in self.left_outs.items(): style = "DataLine" diff --git a/pyxdsm/__init__.py b/pyxdsm/__init__.py index ba51ced..55e4709 100644 --- a/pyxdsm/__init__.py +++ b/pyxdsm/__init__.py @@ -1 +1 @@ -__version__ = "2.2.2" +__version__ = "2.3.0"