Skip to content

Commit 22ccc95

Browse files
committed
Extend topdown test for node dimension calculation
Check that calculated node dimensions correctly include padding in the fallback case of topdown layout where no approximator is set.
1 parent 459e0a1 commit 22ccc95

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/org.eclipse.elk.alg.topdown.test/src/org/eclipse/elk/alg/topdown/test/TopdownLayoutTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
import static org.junit.Assert.assertEquals;
1313
import static org.junit.Assert.fail;
1414

15+
import java.util.EnumSet;
16+
1517
import org.eclipse.elk.alg.test.PlainJavaInitialization;
1618
import org.eclipse.elk.core.LayoutConfigurator;
1719
import org.eclipse.elk.core.RecursiveGraphLayoutEngine;
1820
import org.eclipse.elk.core.UnsupportedGraphException;
1921
import org.eclipse.elk.core.data.LayoutAlgorithmResolver;
2022
import org.eclipse.elk.core.math.ElkPadding;
2123
import org.eclipse.elk.core.options.CoreOptions;
24+
import org.eclipse.elk.core.options.SizeConstraint;
2225
import org.eclipse.elk.core.options.TopdownNodeTypes;
2326
import org.eclipse.elk.core.util.BasicProgressMonitor;
2427
import org.eclipse.elk.core.util.ElkUtil;
@@ -248,4 +251,49 @@ public void testScaleCapBounded() {
248251
// topdown scale factor of toplevel node
249252
assertEquals(3.0, toplevel.getProperty(CoreOptions.TOPDOWN_SCALE_FACTOR), 0.00001);
250253
}
254+
255+
/**
256+
* Tests that paddings are correctly considered when computing the size of nodes with further children.
257+
*/
258+
@Test
259+
public void testChildDimensionCalculation() {
260+
PlainJavaInitialization.initializePlainJavaLayout();
261+
ElkNode graph = ElkGraphUtil.createGraph();
262+
graph.setProperty(CoreOptions.TOPDOWN_LAYOUT, true);
263+
graph.setProperty(CoreOptions.TOPDOWN_NODE_TYPE, TopdownNodeTypes.ROOT_NODE);
264+
265+
ElkNode toplevel = ElkGraphUtil.createNode(graph);
266+
toplevel.setProperty(CoreOptions.TOPDOWN_LAYOUT, true);
267+
toplevel.setProperty(CoreOptions.TOPDOWN_NODE_TYPE, TopdownNodeTypes.HIERARCHICAL_NODE);
268+
toplevel.setProperty(CoreOptions.NODE_SIZE_FIXED_GRAPH_SIZE, true);
269+
toplevel.setProperty(CoreOptions.ALGORITHM, "org.eclipse.elk.layered");
270+
toplevel.setProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_WIDTH, 20.0);
271+
toplevel.setProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO, 1.0);
272+
ElkPadding padding = new ElkPadding(10);
273+
toplevel.setProperty(CoreOptions.PADDING, padding);
274+
275+
ElkNode child1 = ElkGraphUtil.createNode(toplevel);
276+
child1.setProperty(CoreOptions.TOPDOWN_LAYOUT, true);
277+
child1.setProperty(CoreOptions.TOPDOWN_NODE_TYPE, TopdownNodeTypes.HIERARCHICAL_NODE);
278+
child1.setProperty(CoreOptions.NODE_SIZE_FIXED_GRAPH_SIZE, true);
279+
child1.setX(0);
280+
child1.setY(0);
281+
child1.setProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_WIDTH, 20.0);
282+
child1.setProperty(CoreOptions.TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO, 1.0);
283+
284+
285+
// prepare layout engine
286+
LayoutConfigurator config = new LayoutConfigurator();
287+
ElkUtil.applyVisitors(graph, config, new LayoutAlgorithmResolver());
288+
// call layout with layout engine
289+
try {
290+
new RecursiveGraphLayoutEngine().layout(graph, new BasicProgressMonitor());
291+
} catch (UnsupportedGraphException exception) {
292+
fail(exception.toString());
293+
}
294+
295+
// child dimensions computed in fallback case depend on the paddings and the "topdown size"
296+
assertEquals(20.0 + padding.getHorizontal(), toplevel.getWidth(), 0.00001);
297+
assertEquals(20.0 + padding.getVertical(), toplevel.getHeight(), 0.00001);
298+
}
251299
}

0 commit comments

Comments
 (0)