Skip to content

Commit 214ef7c

Browse files
committed
FEAT(PLOT,.TC): +Overwrites+Failed+Canceled
1 parent d1369ed commit 214ef7c

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

graphtik/plot.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ def build_pydot(
166166

167167
steps_thickness = 3
168168
fill_color = "wheat"
169+
failed_color = "LightCoral"
170+
cancel_color = "Grey"
171+
overwrite_color = "SkyBlue"
169172
steps_color = "#009999"
170173
new_clusters = {}
171174

@@ -214,7 +217,11 @@ def get_node_name(a):
214217
# LABEL change with solution.
215218
if solution and nx_node in solution:
216219
kw["style"] = "filled"
217-
kw["fillcolor"] = fill_color
220+
kw["fillcolor"] = (
221+
overwrite_color
222+
if nx_node in getattr(solution, "overwrites", ())
223+
else fill_color
224+
)
218225
## NOTE: SVG tooltips not working without URL:
219226
# https://gitlab.com/graphviz/graphviz/issues/1425
220227
kw["tooltip"] = str(solution.get(nx_node))
@@ -225,9 +232,15 @@ def get_node_name(a):
225232
if steps and nx_node in steps:
226233
kw["penwdth"] = steps_thickness
227234
shape = "egg" if isinstance(nx_node, NetworkOperation) else "oval"
228-
if nx_node in getattr(solution, "executed", ()):
235+
if nx_node in getattr(solution, "failures", ()):
236+
kw["style"] = "filled"
237+
kw["fillcolor"] = failed_color
238+
elif nx_node in getattr(solution, "executed", ()):
229239
kw["style"] = "filled"
230240
kw["fillcolor"] = fill_color
241+
elif nx_node in getattr(solution, "canceled", ()):
242+
kw["style"] = "filled"
243+
kw["fillcolor"] = cancel_color
231244
try:
232245
kw["URL"] = f"file://{inspect.getfile(nx_node.fn)}"
233246
except Exception as ex:

test/test_graphtik.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,15 @@ def test_pruning_multiouts_not_override_intermediates1(exemethod):
504504
assert solution == exp
505505
assert solution.overwrites == {"overidden": [5, 1]}
506506

507+
# Check plotting Overwrites.
508+
assert "SkyBlue" in str(solution.plot())
509+
507510
solution = pipeline.compute(inp1, "asked")
508511
assert solution.overwrites == {}
509512

513+
# Check not plotting Overwrites.
514+
assert "SkyBlue" not in str(solution.plot())
515+
510516

511517
@pytest.mark.xfail(
512518
sys.version_info < (3, 6),
@@ -1103,6 +1109,11 @@ def test_execution_endurance(exemethod):
11031109
sol = graph.compute(inp, outputs=["a+2b", "cc"])
11041110
assert sol == {"a+2b": 5}
11051111

1112+
# Check plotting Fail & Cancel.
1113+
#
1114+
dot = str(sol.plot())
1115+
assert "LightCoral" in dot # failed
1116+
assert "Grey" in dot # Canceled
11061117

11071118
def test_multithreading_plan_execution():
11081119
# From Huygn's test-code given in yahoo/graphkit#31

0 commit comments

Comments
 (0)