From 9fd2c6cad0cff93ea95e7b1f63f65a439c6e6e80 Mon Sep 17 00:00:00 2001 From: peterbaumert Date: Thu, 17 Aug 2023 18:52:56 +0200 Subject: [PATCH 1/4] make graph direction configurable --- joeflow/conf.py | 5 +++++ joeflow/models.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/joeflow/conf.py b/joeflow/conf.py index 97935e7..94bf2ae 100644 --- a/joeflow/conf.py +++ b/joeflow/conf.py @@ -30,3 +30,8 @@ class JoeflowAppConfig(AppConf): """ Queue name in which all machine tasks will be queued. """ + + JOEFLOW_GRAPH_DIRECTION = "LR" + """ + Direction in which to render graph. LR|TD|... + """ diff --git a/joeflow/models.py b/joeflow/models.py index 9df45b6..b4ddc75 100644 --- a/joeflow/models.py +++ b/joeflow/models.py @@ -194,7 +194,7 @@ def get_graph(cls, color="black"): """ graph = NoDashDiGraph() - graph.attr("graph", rankdir="LR") + graph.attr("graph", rankdir=settings.JOEFLOW_GRAPH_DIRECTION) graph.attr( "node", _attributes=dict( From fc9a1ffdefb744336e6f5c63293828de79cbe0a8 Mon Sep 17 00:00:00 2001 From: peterbaumert Date: Mon, 28 Aug 2023 10:27:22 +0200 Subject: [PATCH 2/4] make rankdir a class variable --- joeflow/conf.py | 5 ----- joeflow/models.py | 4 +++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/joeflow/conf.py b/joeflow/conf.py index 94bf2ae..97935e7 100644 --- a/joeflow/conf.py +++ b/joeflow/conf.py @@ -30,8 +30,3 @@ class JoeflowAppConfig(AppConf): """ Queue name in which all machine tasks will be queued. """ - - JOEFLOW_GRAPH_DIRECTION = "LR" - """ - Direction in which to render graph. LR|TD|... - """ diff --git a/joeflow/models.py b/joeflow/models.py index b4ddc75..c53db9d 100644 --- a/joeflow/models.py +++ b/joeflow/models.py @@ -66,6 +66,8 @@ 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" + task_set = GenericRelation( "joeflow.Task", object_id_field="_workflow_id", for_concrete_model=False ) @@ -194,7 +196,7 @@ def get_graph(cls, color="black"): """ graph = NoDashDiGraph() - graph.attr("graph", rankdir=settings.JOEFLOW_GRAPH_DIRECTION) + graph.attr("graph", rankdir=cls.rankdir) graph.attr( "node", _attributes=dict( From 9a95c4ebb05952ec7898116d03eb6b8f851d08a0 Mon Sep 17 00:00:00 2001 From: peterbaumert Date: Mon, 28 Aug 2023 10:52:48 +0200 Subject: [PATCH 3/4] add test --- tests/test_models.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_models.py b/tests/test_models.py index 7bd5135..a9ed4e8 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -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 isinstance(graph, Digraph) + def test_get_graph_svg(self, fixturedir): svg = workflows.SimpleWorkflow.get_graph_svg() assert isinstance(svg, SafeString) From 7a6de12bcfbaf355547e6765bd87d37f30a3aa71 Mon Sep 17 00:00:00 2001 From: Johannes Maron Date: Tue, 29 Aug 2023 09:44:34 +0200 Subject: [PATCH 4/4] Add docs and improve tests --- docs/core_components.rst | 1 + joeflow/models.py | 1 + tests/test_models.py | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/core_components.rst b/docs/core_components.rst index 3b9c40c..f4a6d4b 100644 --- a/docs/core_components.rst +++ b/docs/core_components.rst @@ -46,6 +46,7 @@ Advanced Workflow API :show-inheritance: :members: urls, + rankdir, get_graph_svg, get_instance_graph_svg, get_absolute_url, diff --git a/joeflow/models.py b/joeflow/models.py index c53db9d..1ff6ece 100644 --- a/joeflow/models.py +++ b/joeflow/models.py @@ -67,6 +67,7 @@ class Workflow(models.Model, metaclass=WorkflowBase): 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 diff --git a/tests/test_models.py b/tests/test_models.py index a9ed4e8..d8801af 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -114,7 +114,7 @@ def test_get_graph(self, fixturedir): def test_change_graph_direction(self, fixturedir): workflows.SimpleWorkflow.rankdir = "TD" graph = workflows.SimpleWorkflow.get_graph() - assert isinstance(graph, Digraph) + assert "rankdir=TD" in str(graph) def test_get_graph_svg(self, fixturedir): svg = workflows.SimpleWorkflow.get_graph_svg()