|
12 | 12 | import static org.junit.Assert.assertEquals; |
13 | 13 | import static org.junit.Assert.fail; |
14 | 14 |
|
| 15 | +import java.util.EnumSet; |
| 16 | + |
15 | 17 | import org.eclipse.elk.alg.test.PlainJavaInitialization; |
16 | 18 | import org.eclipse.elk.core.LayoutConfigurator; |
17 | 19 | import org.eclipse.elk.core.RecursiveGraphLayoutEngine; |
18 | 20 | import org.eclipse.elk.core.UnsupportedGraphException; |
19 | 21 | import org.eclipse.elk.core.data.LayoutAlgorithmResolver; |
20 | 22 | import org.eclipse.elk.core.math.ElkPadding; |
21 | 23 | import org.eclipse.elk.core.options.CoreOptions; |
| 24 | +import org.eclipse.elk.core.options.SizeConstraint; |
22 | 25 | import org.eclipse.elk.core.options.TopdownNodeTypes; |
23 | 26 | import org.eclipse.elk.core.util.BasicProgressMonitor; |
24 | 27 | import org.eclipse.elk.core.util.ElkUtil; |
@@ -248,4 +251,49 @@ public void testScaleCapBounded() { |
248 | 251 | // topdown scale factor of toplevel node |
249 | 252 | assertEquals(3.0, toplevel.getProperty(CoreOptions.TOPDOWN_SCALE_FACTOR), 0.00001); |
250 | 253 | } |
| 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 | + } |
251 | 299 | } |
0 commit comments