Skip to content

Commit f28fbc7

Browse files
authored
Top-down layout patch + blog post (#932)
* blog draft and algorithm renaming * Adjust junction points in top-down layout. Signed-off-by: Max Kasperowski <[email protected]> * update blog post --------- Signed-off-by: Max Kasperowski <[email protected]>
1 parent fea92fa commit f28fbc7

File tree

7 files changed

+730
-1
lines changed

7 files changed

+730
-1
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: "Top-down Layout: Zoom in the Layout Process"
3+
menu:
4+
main:
5+
identifier: "23-06-09-topdown-layout"
6+
parent: "2023"
7+
weight: 10
8+
---
9+
10+
_By Maximilian Kasperowski, June 9, 2023_
11+
12+
The coming update (ELK 0.9.0) introduces a new approach to layout hierarchical graphs. Instead of increasing the size of parent nodes to fit their content we apply scaling to the content to make it fit the parent. In this post I will go over the new properties provided to achieve this and what kinds of output can be produced using top-down layout.
13+
14+
## Scaling
15+
In addition to the existing data assigned to graph elements during layout such as positions, nodes can now also have the additional property `org.eclipse.elk.topdown.scaleFactor`. The scale factor tells the renderer what the relative scale of the sub-layout of the node should be. The renderer needs to apply the scaling as illustrated in the following figure.
16+
{{<image src="top-down-scaling.png" alt="application of top-down scale factor." width="100%">}}
17+
18+
The following graph demonstrates the scale factor. The top-level red node contains a layered layout that consists of two nodes. We have assigned it a fixed width and height and in order to fit the children the computed scale factor is applied around all the children as a group. In the svg this is realized by wrapping the children in a `<g>` tag with a `transform="scale(scaleFactor)` attribute.
19+
{{< image src="topdown-example.svg" alt="top-down layout example." width="200%">}}
20+
21+
## Usage
22+
In general there are many ways that top-down layout can be configured. I will demonstrate two main approaches that showcase all possible options in some typical configurations.
23+
24+
### Scale all hierarchy levels
25+
The first simple method is to apply some scale factor for each sublayout. This means that for each node we first set its dimensions (independent of the sublayout) and then, after layouting the children, scale the sublayout so that it fits the parent. To do this we set the following properties:
26+
27+
For all nodes:
28+
- `org.eclipse.elk.topdownLayout=true`
29+
30+
For the root node:
31+
- `org.eclipse.elk.topdown.nodeType=ROOT_NODE`
32+
33+
For all other nodes:
34+
- `org.eclipse.elk.topdown.nodeType=HIERARCHICAL_NODE`
35+
- `org.eclipse.elk.nodeSize.fixedGraphSize=true`
36+
- `org.eclipse.elk.algorithm` must be set to an algorithm that supports `org.eclipse.elk.nodeSize.fixedGraphSize`
37+
38+
### Mixing scaling approach
39+
Another approach that can be used for certain graph types utilizes the `PARALLEL_NODE` node type. Using this prevents scaling on certain parts of the diagram hierarchy to retain more control over the look of the graph. Due to algorithmic limitations, this approach only works when we have *region-like* nodes, i.e., nodes that are not connected via edges and should be simply packed in some manner.
40+
41+
The two examples shown below are obtained by configuring the properties in the following way:
42+
43+
For all nodes:
44+
- `org.eclipse.elk.topdownLayout=true`
45+
46+
For the root node:
47+
- `org.eclipse.elk.topdown.nodeType=ROOT_NODE`
48+
49+
For all white regions:
50+
- `org.eclipse.elk.topdown.nodeType=HIERARCHICAL_NODE`
51+
- `org.eclipse.elk.nodeSize.fixedGraphSize=true`
52+
- `org.eclipse.elk.algorithm` must be set to an algorithm that supports `org.eclipse.elk.nodeSize.fixedGraphSize`
53+
54+
For all blue states:
55+
- `org.eclipse.elk.topdown.nodeType=PARALLEL_NODE`
56+
- `org.eclipse.elk.algorithm=topdownpacking`
57+
- `org.eclipse.elk.topdown.hierarchicalNodeWidth=200`
58+
- `org.eclipse.elk.topdown.hierarchicalNodeAspectRatio=1.4`
59+
60+
{{<image src="wagon-topdown.png" alt="example of top-down layout on wagon scchart." width="100%">}}
61+
62+
{{<image src="controller-topdown.png" alt="example of top-down layout on controller scchart." width="100%">}}
195 KB
Loading
33.3 KB
Loading

docs/static/img/topdown-example.svg

Lines changed: 659 additions & 0 deletions
Loading

docs/static/img/wagon-topdown.png

67.6 KB
Loading

plugins/org.eclipse.elk.alg.topdownpacking/src/org/eclipse/elk/alg/topdownpacking/Topdownpacking.melk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bundle {
2020
}
2121

2222
algorithm topdownpacking(TopdownpackingLayoutProvider) {
23-
label "Topdownpacking"
23+
label "ELK Top-down Packing"
2424
description "An algorithm for placing boxes of fixed sizes. Expands boxes horizontally to fill empty
2525
whitespace. This algorithm can be used standalone or specifically for
2626
{@link CoreOptions.TOPDOWN_LAYOUT}. In this use case it should be set for nodes whose

plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/RecursiveGraphLayoutEngine.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.eclipse.elk.core.data.LayoutAlgorithmResolver;
2020
import org.eclipse.elk.core.math.ElkPadding;
2121
import org.eclipse.elk.core.math.KVector;
22+
import org.eclipse.elk.core.math.KVectorChain;
2223
import org.eclipse.elk.core.options.ContentAlignment;
2324
import org.eclipse.elk.core.options.CoreOptions;
2425
import org.eclipse.elk.core.options.HierarchyHandling;
@@ -373,6 +374,13 @@ protected List<ElkEdge> layoutRecursively(final ElkNode layoutNode, final TestCo
373374
for (ElkLabel label : edge.getLabels()) {
374375
label.setLocation(label.getX() + xShift, label.getY() + yShift);
375376
}
377+
// shift junction points
378+
KVectorChain junctionPoints = edge.getProperty(CoreOptions.JUNCTION_POINTS);
379+
for (KVector junctionPoint : junctionPoints) {
380+
junctionPoint.x += xShift;
381+
junctionPoint.y += yShift;
382+
}
383+
edge.setProperty(CoreOptions.JUNCTION_POINTS, junctionPoints);
376384
}
377385
}
378386
topdownLayoutMonitor.done();

0 commit comments

Comments
 (0)