Skip to content

Commit

Permalink
Write container property into edges only in CONTAINER mode
Browse files Browse the repository at this point in the history
Also, mention this in the docs.
  • Loading branch information
skieffer committed Aug 29, 2024
1 parent 5d7cf1a commit 2312415
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ class EdgeCoordsTest {
"incomingShape": "y",
"outgoingShape": "z"
}
],
"container": "B"
]
},
{
"id": "e2",
Expand Down Expand Up @@ -464,8 +463,7 @@ class EdgeCoordsTest {
"incomingShape": "x",
"outgoingShape": "z"
}
],
"container": "A"
]
},
{
"id": "e3",
Expand All @@ -489,8 +487,7 @@ class EdgeCoordsTest {
"incomingShape": "x",
"outgoingShape": "p"
}
],
"container": "A"
]
},
{
"id": "e4",
Expand All @@ -514,8 +511,7 @@ class EdgeCoordsTest {
"incomingShape": "p",
"outgoingShape": "y"
}
],
"container": "B"
]
}
],
"x": 143,
Expand Down Expand Up @@ -625,8 +621,7 @@ class EdgeCoordsTest {
"incomingShape": "y",
"outgoingShape": "z"
}
],
"container": "B"
]
},
{
"id": "e2",
Expand Down Expand Up @@ -677,8 +672,7 @@ class EdgeCoordsTest {
"incomingShape": "x",
"outgoingShape": "z"
}
],
"container": "A"
]
},
{
"id": "e3",
Expand All @@ -702,8 +696,7 @@ class EdgeCoordsTest {
"incomingShape": "x",
"outgoingShape": "p"
}
],
"container": "A"
]
},
{
"id": "e4",
Expand All @@ -727,8 +720,7 @@ class EdgeCoordsTest {
"incomingShape": "p",
"outgoingShape": "y"
}
],
"container": "B"
]
}
],
"x": 143,
Expand Down Expand Up @@ -1051,8 +1043,7 @@ class EdgeCoordsTest {
"incomingShape": "y",
"outgoingShape": "z"
}
],
"container": "B"
]
},
{
"id": "e2",
Expand Down Expand Up @@ -1103,8 +1094,7 @@ class EdgeCoordsTest {
"incomingShape": "x",
"outgoingShape": "z"
}
],
"container": "A"
]
},
{
"id": "e3",
Expand All @@ -1128,8 +1118,7 @@ class EdgeCoordsTest {
"incomingShape": "x",
"outgoingShape": "p"
}
],
"container": "A"
]
},
{
"id": "e4",
Expand All @@ -1153,8 +1142,7 @@ class EdgeCoordsTest {
"incomingShape": "p",
"outgoingShape": "y"
}
],
"container": "B"
]
}
],
"x": 155,
Expand Down Expand Up @@ -1265,8 +1253,7 @@ class EdgeCoordsTest {
"incomingShape": "y",
"outgoingShape": "z"
}
],
"container": "B"
]
},
{
"id": "e2",
Expand Down Expand Up @@ -1317,8 +1304,7 @@ class EdgeCoordsTest {
"incomingShape": "x",
"outgoingShape": "z"
}
],
"container": "A"
]
},
{
"id": "e3",
Expand All @@ -1342,8 +1328,7 @@ class EdgeCoordsTest {
"incomingShape": "x",
"outgoingShape": "p"
}
],
"container": "A"
]
},
{
"id": "e4",
Expand All @@ -1367,8 +1352,7 @@ class EdgeCoordsTest {
"incomingShape": "p",
"outgoingShape": "y"
}
],
"container": "B"
]
}
],
"x": 155,
Expand Down

0 comments on commit 2312415

Please sign in to comment.