From 2312415726ef20615cf31c65d6993ce1aad241a8 Mon Sep 17 00:00:00 2001 From: Steve Kieffer Date: Thu, 29 Aug 2024 18:01:08 -0400 Subject: [PATCH] Write `container` property into edges only in CONTAINER mode Also, mention this in the docs. --- .../graphdatastructure/coordinatesystem.md | 16 ++++--- .../eclipse/elk/graph/json/JsonImporter.xtend | 4 +- .../elk/graph/json/test/EdgeCoordsTest.xtend | 48 +++++++------------ 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/docs/content/documentation/tooldevelopers/graphdatastructure/coordinatesystem.md b/docs/content/documentation/tooldevelopers/graphdatastructure/coordinatesystem.md index aa6375f97..3e1016b19 100644 --- a/docs/content/documentation/tooldevelopers/graphdatastructure/coordinatesystem.md +++ b/docs/content/documentation/tooldevelopers/graphdatastructure/coordinatesystem.md @@ -49,12 +49,16 @@ There are four possible values: * `PARENT`: Coordinates are relative to the node in which the edge was defined in the given JSON. * `ROOT`: Coordinates are relative to the root node, i.e. global coordinates. -The default value is `INHERIT`, except at the root node, where the default is `CONTAINER`. +The default value is `INHERIT`, except at the root node, where the default is (for historical reasons) `CONTAINER`. Thus, the default behavior is as described at the top of this page. -Edge containment is a tricky subject, and the definition of an edge's proper container is given at the end -of the page on the +The definition of an edge's proper container is given at the end of the page on the [_Graph Data Structure_]({{< relref "documentation/tooldevelopers/graphdatastructure.md" >}}). -Since you are allowed to define an edge under any node whatsoever in the input JSON, the edge's *parent* node -(the one it is defined under) may be different from the edge's *container*. Therefore, while `CONTAINER` is the -default mode for historical reasons, users may find it easier to use `PARENT` or `ROOT`. +It involves lowest common ancestors, and can be tricky to compute correctly. +In particular, since you are allowed to define an edge under any node whatsoever in the input JSON, the edge's +*parent* node (the one it is defined under) may be different from its container. + +If you elect to work in `CONTAINER` mode, ELK helps you by writing a `container` property into each edge after layout, +giving the `id` of the edge's container node. This can then be used to interpret the coordinates. + +If you elect to work in `PARENT` or `ROOT` mode instead, then you do not need to know about edge containers at all. diff --git a/plugins/org.eclipse.elk.graph.json/src/org/eclipse/elk/graph/json/JsonImporter.xtend b/plugins/org.eclipse.elk.graph.json/src/org/eclipse/elk/graph/json/JsonImporter.xtend index cfab6696b..99dfb6418 100644 --- a/plugins/org.eclipse.elk.graph.json/src/org/eclipse/elk/graph/json/JsonImporter.xtend +++ b/plugins/org.eclipse.elk.graph.json/src/org/eclipse/elk/graph/json/JsonImporter.xtend @@ -670,7 +670,9 @@ final class JsonImporter { } } - jsonObj.addJsonObj("container", edge.getContainingNode.identifier) + if (edge.originalParent.edgeCoordsMode === EdgeCoords.CONTAINER) { + jsonObj.addJsonObj("container", edge.getContainingNode.identifier) + } } private def dispatch transferLayoutInt2(ElkLabel label) { diff --git a/test/org.eclipse.elk.graph.json.test/src/org/eclipse/elk/graph/json/test/EdgeCoordsTest.xtend b/test/org.eclipse.elk.graph.json.test/src/org/eclipse/elk/graph/json/test/EdgeCoordsTest.xtend index 7945510cd..7a1d2a05f 100644 --- a/test/org.eclipse.elk.graph.json.test/src/org/eclipse/elk/graph/json/test/EdgeCoordsTest.xtend +++ b/test/org.eclipse.elk.graph.json.test/src/org/eclipse/elk/graph/json/test/EdgeCoordsTest.xtend @@ -412,8 +412,7 @@ class EdgeCoordsTest { "incomingShape": "y", "outgoingShape": "z" } - ], - "container": "B" + ] }, { "id": "e2", @@ -464,8 +463,7 @@ class EdgeCoordsTest { "incomingShape": "x", "outgoingShape": "z" } - ], - "container": "A" + ] }, { "id": "e3", @@ -489,8 +487,7 @@ class EdgeCoordsTest { "incomingShape": "x", "outgoingShape": "p" } - ], - "container": "A" + ] }, { "id": "e4", @@ -514,8 +511,7 @@ class EdgeCoordsTest { "incomingShape": "p", "outgoingShape": "y" } - ], - "container": "B" + ] } ], "x": 143, @@ -625,8 +621,7 @@ class EdgeCoordsTest { "incomingShape": "y", "outgoingShape": "z" } - ], - "container": "B" + ] }, { "id": "e2", @@ -677,8 +672,7 @@ class EdgeCoordsTest { "incomingShape": "x", "outgoingShape": "z" } - ], - "container": "A" + ] }, { "id": "e3", @@ -702,8 +696,7 @@ class EdgeCoordsTest { "incomingShape": "x", "outgoingShape": "p" } - ], - "container": "A" + ] }, { "id": "e4", @@ -727,8 +720,7 @@ class EdgeCoordsTest { "incomingShape": "p", "outgoingShape": "y" } - ], - "container": "B" + ] } ], "x": 143, @@ -1051,8 +1043,7 @@ class EdgeCoordsTest { "incomingShape": "y", "outgoingShape": "z" } - ], - "container": "B" + ] }, { "id": "e2", @@ -1103,8 +1094,7 @@ class EdgeCoordsTest { "incomingShape": "x", "outgoingShape": "z" } - ], - "container": "A" + ] }, { "id": "e3", @@ -1128,8 +1118,7 @@ class EdgeCoordsTest { "incomingShape": "x", "outgoingShape": "p" } - ], - "container": "A" + ] }, { "id": "e4", @@ -1153,8 +1142,7 @@ class EdgeCoordsTest { "incomingShape": "p", "outgoingShape": "y" } - ], - "container": "B" + ] } ], "x": 155, @@ -1265,8 +1253,7 @@ class EdgeCoordsTest { "incomingShape": "y", "outgoingShape": "z" } - ], - "container": "B" + ] }, { "id": "e2", @@ -1317,8 +1304,7 @@ class EdgeCoordsTest { "incomingShape": "x", "outgoingShape": "z" } - ], - "container": "A" + ] }, { "id": "e3", @@ -1342,8 +1328,7 @@ class EdgeCoordsTest { "incomingShape": "x", "outgoingShape": "p" } - ], - "container": "A" + ] }, { "id": "e4", @@ -1367,8 +1352,7 @@ class EdgeCoordsTest { "incomingShape": "p", "outgoingShape": "y" } - ], - "container": "B" + ] } ], "x": 155,