Skip to content

Commit

Permalink
Better display of conditionals on workflow diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
pfebrer committed Jan 1, 2024
1 parent f6b6af4 commit 117ca49
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/sisl/nodes/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,10 @@ def _maybe_autoupdate(self):
if not self.context["lazy"]:
self.get()

def get_diagram_label(self):
"""Returns the label to be used in diagrams when displaying this node."""
return None

Check warning on line 682 in src/sisl/nodes/node.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/nodes/node.py#L682

Added line #L682 was not covered by tests


class DummyInputValue(Node):
"""A dummy node that can be used as a placeholder for input values."""
Expand Down
18 changes: 18 additions & 0 deletions src/sisl/nodes/syntax_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,26 @@ def _receive_outdated(self):
def function(test, true, false):
return true if test else false

def get_diagram_label(self):
"""Returns the label to be used in diagrams when displaying this node."""
return "if/else"

Check warning on line 116 in src/sisl/nodes/syntax_nodes.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/nodes/syntax_nodes.py#L116

Added line #L116 was not covered by tests


class CompareSyntaxNode(SyntaxNode):
_op_to_symbol = {
"eq": "==",
"ne": "!=",
"gt": ">",
"lt": "<",
"ge": ">=",
"le": "<=",
None: "compare",
}

@staticmethod
def function(left, op: str, right):
return getattr(operator, op)(left, right)

def get_diagram_label(self):
"""Returns the label to be used in diagrams when displaying this node."""
return self._op_to_symbol.get(self._prev_evaluated_inputs.get("op"))

Check warning on line 136 in src/sisl/nodes/syntax_nodes.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/nodes/syntax_nodes.py#L136

Added line #L136 was not covered by tests
4 changes: 3 additions & 1 deletion src/sisl/nodes/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,9 @@ def rgb2gray(rgb):
for node in nodes:
graph_node = graph.nodes[node]

node_obj = self._workflow.dryrun_nodes.get(node)

Check warning on line 346 in src/sisl/nodes/workflow.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/nodes/workflow.py#L346

Added line #L346 was not covered by tests

if node_help:
node_obj = self._workflow.dryrun_nodes.get(node)
title = (
_get_node_inputs_str(node_obj) if node_obj is not None else ""
)
Expand All @@ -359,6 +360,7 @@ def rgb2gray(rgb):
"level": level,
"title": title,
"font": font,
"label": node_obj.get_diagram_label(),
**node_props,
}
)
Expand Down

0 comments on commit 117ca49

Please sign in to comment.