Skip to content

Commit

Permalink
Add class attribute to change the graph direction (#90)
Browse files Browse the repository at this point in the history

Co-authored-by: Johannes Maron <johannes@maron.family>
  • Loading branch information
peterbaumert and codingjoe authored Aug 29, 2023
1 parent 8d58695 commit 0906fb5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/core_components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Advanced Workflow API
:show-inheritance:
:members:
urls,
rankdir,
get_graph_svg,
get_instance_graph_svg,
get_absolute_url,
Expand Down
5 changes: 4 additions & 1 deletion joeflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class Workflow(models.Model, metaclass=WorkflowBase):
created = models.DateTimeField(auto_now_add=True, db_index=True)
modified = models.DateTimeField(auto_now=True, db_index=True)

rankdir = "LR"
"""Direction of the workflow's graph visualization."""

task_set = GenericRelation(
"joeflow.Task", object_id_field="_workflow_id", for_concrete_model=False
)
Expand Down Expand Up @@ -194,7 +197,7 @@ def get_graph(cls, color="black"):
"""
graph = NoDashDiGraph()
graph.attr("graph", rankdir="LR")
graph.attr("graph", rankdir=cls.rankdir)
graph.attr(
"node",
_attributes=dict(
Expand Down
5 changes: 5 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ def test_get_graph(self, fixturedir):
print(str(graph))
assert set(str(graph).splitlines()) == set(expected_graph)

def test_change_graph_direction(self, fixturedir):
workflows.SimpleWorkflow.rankdir = "TD"
graph = workflows.SimpleWorkflow.get_graph()
assert "rankdir=TD" in str(graph)

def test_get_graph_svg(self, fixturedir):
svg = workflows.SimpleWorkflow.get_graph_svg()
assert isinstance(svg, SafeString)
Expand Down

0 comments on commit 0906fb5

Please sign in to comment.