Skip to content

Commit

Permalink
configurability
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed Mar 3, 2024
1 parent 374a631 commit e41f5a5
Showing 1 changed file with 55 additions and 14 deletions.
69 changes: 55 additions & 14 deletions examples/wdlviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,30 @@ def main(args=None):
)
parser.add_argument("--inputs", action="store_true", help="include input declarations")
parser.add_argument("--outputs", action="store_true", help="include output declarations")
parser.add_argument(
"--rankdir",
choices=("LR", "RL", "TB", "BT"),
default="LR",
help="layout orientation (default: LR)",
)
parser.add_argument(
"--splines",
choices=("spline", "curved", "compound", "ortho"),
default="compound",
help="edge shape (default: compound)",
)
parser.add_argument(
"--no-subworkflow-edges",
dest="subworkflow_edges",
action="store_false",
help="hide dotted edges from call to subworkflow",
)
parser.add_argument(
"--no-render",
dest="render",
action="store_false",
help="skip rendering; just print the graphviz source",
)
parser.add_argument(
"--no-quant-check",
dest="check_quant",
Expand All @@ -55,12 +73,17 @@ def main(args=None):
assert doc.workflow, "No workflow in WDL document"

# visualize workflow
dot = wdlviz(doc.workflow, args.inputs, args.outputs, args.subworkflow_edges)
dot = wdlviz(
doc.workflow, args.rankdir, args.splines, args.inputs, args.outputs, args.subworkflow_edges
)
print(dot.source)
dot.render(doc.workflow.name + ".dot", view=True)
if args.render:
dot.render(doc.workflow.name + ".dot", view=True)


def wdlviz(workflow: WDL.Workflow, inputs=False, outputs=False, subworkflow_edges=True):
def wdlviz(
workflow: WDL.Workflow, rankdir, splines, inputs=False, outputs=False, subworkflow_edges=True
):
"""
Project the workflow's built-in dependency graph onto a graphviz representation
"""
Expand All @@ -71,7 +94,15 @@ def wdlviz(workflow: WDL.Workflow, inputs=False, outputs=False, subworkflow_edge
# initialiaze Digraph
fontname = "Roboto"
top = graphviz.Digraph()
top.attr(label=workflow.name, labelloc="t", fontname=fontname, compound="true", rankdir="LR")
top.attr(
label=workflow.name,
labelloc="t",
fontname=fontname,
compound="true",
rankdir=rankdir,
concentrate="true",
splines=splines,
)
top.attr("node", fontname=fontname)
top.attr("edge", color="#00000080")

Expand Down Expand Up @@ -105,24 +136,25 @@ def add_node(graph: graphviz.Digraph, node: WDL.WorkflowNode):
subworkflows_visited.add(id(node.callee))
with top.subgraph(name=f"cluster-{id(node.callee)}") as sg:
sg.attr(label=node.callee.name, fontname=fontname, rank="max")
sg.node( # sink
str(id(node.callee)),
"",
style="invis",
height="0",
width="0",
margin="0",
)
add_workflow(sg, node.callee)
# dotted connection from call to subworkflow
top.edge(
# dotted edge from call to subworkflow
graph.edge(
f"{id(node)}:s",
f"{id(node.callee)}:n",
lhead=f"cluster-{id(node.callee)}",
style="dotted" if subworkflow_edges else "invis",
arrowhead="none",
constraint="false",
)
# invisible edge for subworkflow hierarchy
top.edge(
f"{id(workflow)}",
f"{id(node.callee)}",
style="invis",
height="0",
width="0",
margin="0",
)
name = f"{node.callee.name} as {name}"
# node for call or decl
graph.node(
Expand Down Expand Up @@ -171,6 +203,15 @@ def add_workflow(graph, workflow):
nodes_visited.add(outp.workflow_node_id)
sg.attr(label="outputs", fontname=fontname)

graph.node( # sink
str(id(workflow)),
"",
style="invis",
height="0",
width="0",
margin="0",
)

for node in (workflow.inputs or []) + workflow.body + (workflow.outputs or []):
add_edges(graph, workflow, node)

Expand Down

0 comments on commit e41f5a5

Please sign in to comment.