Skip to content

Commit

Permalink
Change logic for auto-fading connections (#53)
Browse files Browse the repository at this point in the history
* 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 <lamkina@umich.edu>
  • Loading branch information
A-CGray and lamkina authored May 17, 2023
1 parent a5eb8eb commit c219b15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions pyxdsm/XDSM.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand All @@ -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.
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pyxdsm/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.2.2"
__version__ = "2.3.0"

0 comments on commit c219b15

Please sign in to comment.