Skip to content

Commit 0906fb5

Browse files
Add class attribute to change the graph direction (#90)
Co-authored-by: Johannes Maron <[email protected]>
1 parent 8d58695 commit 0906fb5

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Diff for: docs/core_components.rst

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Advanced Workflow API
4646
:show-inheritance:
4747
:members:
4848
urls,
49+
rankdir,
4950
get_graph_svg,
5051
get_instance_graph_svg,
5152
get_absolute_url,

Diff for: joeflow/models.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class Workflow(models.Model, metaclass=WorkflowBase):
6666
created = models.DateTimeField(auto_now_add=True, db_index=True)
6767
modified = models.DateTimeField(auto_now=True, db_index=True)
6868

69+
rankdir = "LR"
70+
"""Direction of the workflow's graph visualization."""
71+
6972
task_set = GenericRelation(
7073
"joeflow.Task", object_id_field="_workflow_id", for_concrete_model=False
7174
)
@@ -194,7 +197,7 @@ def get_graph(cls, color="black"):
194197
195198
"""
196199
graph = NoDashDiGraph()
197-
graph.attr("graph", rankdir="LR")
200+
graph.attr("graph", rankdir=cls.rankdir)
198201
graph.attr(
199202
"node",
200203
_attributes=dict(

Diff for: tests/test_models.py

+5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ def test_get_graph(self, fixturedir):
111111
print(str(graph))
112112
assert set(str(graph).splitlines()) == set(expected_graph)
113113

114+
def test_change_graph_direction(self, fixturedir):
115+
workflows.SimpleWorkflow.rankdir = "TD"
116+
graph = workflows.SimpleWorkflow.get_graph()
117+
assert "rankdir=TD" in str(graph)
118+
114119
def test_get_graph_svg(self, fixturedir):
115120
svg = workflows.SimpleWorkflow.get_graph_svg()
116121
assert isinstance(svg, SafeString)

0 commit comments

Comments
 (0)