Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mermaid with one job (in a flow) #350

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/jobflow/utils/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def add_cluster(nested_flow, outer_graph):
return pydot_graph


def to_mermaid(flow: jobflow.Flow, show_flow_boxes: bool = False) -> str:
def to_mermaid(flow: jobflow.Flow | jobflow.Job, show_flow_boxes: bool = False) -> str:
"""
Convert a flow to a mermaid graph.

Expand All @@ -190,8 +190,8 @@ def to_mermaid(flow: jobflow.Flow, show_flow_boxes: bool = False) -> str:

Parameters
----------
flow : Flow
A flow.
flow : Flow or a Job
A flow or a job.
show_flow_boxes : bool
Whether to show the boxes around nested flows.

Expand All @@ -215,7 +215,10 @@ def to_mermaid(flow: jobflow.Flow, show_flow_boxes: bool = False) -> str:

To render the graph, go to mermaid.live and paste the contents of ``graph_source``.
"""
from jobflow import Flow
from jobflow import Flow, Job

if isinstance(flow, Job):
flow = Flow(jobs=[flow])

lines = ["flowchart TD"]
nodes = flow.graph.nodes(data=True)
Expand Down Expand Up @@ -243,8 +246,7 @@ def add_subgraph(nested_flow, indent_level=1):
if show_flow_boxes:
lines.append(f"{prefix}end")
else:
if indent_level != 1:
lines.append(f"{prefix}{job.uuid}({job.name})")
lines.append(f"{prefix}{job.uuid}({job.name})")

add_subgraph(flow)

Expand Down