Skip to content

Commit

Permalink
Add support for handling top-down layout when no approximator is set (#…
Browse files Browse the repository at this point in the history
…1089)

* Add support for handling top-down layout when no approximator is set

* Update topdown layout test to handle the case when no approximators are
set correctly.

* Remove commented old code
  • Loading branch information
Eddykasp authored Dec 9, 2024
1 parent 95417f0 commit 83f94c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ protected List<ElkEdge> layoutRecursively(final ElkNode layoutNode, final TestCo
ElkPadding padding = childNode.getProperty(CoreOptions.PADDING);
childNode.setDimensions(Math.max(childNode.getWidth(), size.x + padding.left + padding.right),
Math.max(childNode.getHeight(), size.y + padding.top + padding.bottom));
} else {
// If no approximator is set, use the set sizes for atomic nodes and use the properties
// that have been set for nodes containing further children
if (childNode.getChildren().size() != 0) {
childNode.setDimensions(
layoutNode.getProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_WIDTH),
layoutNode.getProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_WIDTH) /
layoutNode.getProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Kiel University and others.
* Copyright (c) 2022-2024 Kiel University and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -51,8 +51,9 @@ public void testTwoLevelLayoutHorizontalScaling() {
toplevel.setProperty(CoreOptions.ALGORITHM, "org.eclipse.elk.fixed");
toplevel.setProperty(CoreOptions.PADDING, new ElkPadding());
toplevel.setProperty(CoreOptions.SPACING_NODE_NODE, 0.0);
// set size of node so that children will be scaled down
toplevel.setDimensions(20, 50);
// set size of node so that children will be scaled down
graph.setProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_WIDTH, 20.0);
graph.setProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO, 0.4);

ElkNode child1 = ElkGraphUtil.createNode(toplevel);
child1.setProperty(CoreOptions.TOPDOWN_LAYOUT, true);
Expand Down Expand Up @@ -105,7 +106,8 @@ public void testTwoLevelLayoutVerticalScaling() {
toplevel.setProperty(CoreOptions.PADDING, new ElkPadding());
toplevel.setProperty(CoreOptions.SPACING_NODE_NODE, 0.0);
// set size of node so that children will be scaled down
toplevel.setDimensions(40, 30);
graph.setProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_WIDTH, 40.0);
graph.setProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO, 1.33333);

ElkNode child1 = ElkGraphUtil.createNode(toplevel);
child1.setProperty(CoreOptions.TOPDOWN_LAYOUT, true);
Expand Down Expand Up @@ -159,7 +161,8 @@ public void testScaleCap() {
toplevel.setProperty(CoreOptions.PADDING, new ElkPadding());
toplevel.setProperty(CoreOptions.SPACING_NODE_NODE, 0.0);
// set size of node so that children will be scaled down
toplevel.setDimensions(300, 300);
graph.setProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_WIDTH, 300.0);
graph.setProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO, 1.0);

ElkNode child1 = ElkGraphUtil.createNode(toplevel);
child1.setProperty(CoreOptions.TOPDOWN_LAYOUT, true);
Expand Down Expand Up @@ -212,7 +215,8 @@ public void testScaleCapBounded() {
toplevel.setProperty(CoreOptions.PADDING, new ElkPadding());
toplevel.setProperty(CoreOptions.SPACING_NODE_NODE, 0.0);
// set size of node so that children will be scaled down
toplevel.setDimensions(300, 300);
graph.setProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_WIDTH, 300.0);
graph.setProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO, 1.0);

ElkNode child1 = ElkGraphUtil.createNode(toplevel);
child1.setProperty(CoreOptions.TOPDOWN_LAYOUT, true);
Expand Down

0 comments on commit 83f94c8

Please sign in to comment.