@@ -101,4 +101,38 @@ public void GraphSizeCalculationTest() {
101101 assertEquals (paddingLeft + nodeWidth + nodeNodeSpacing + nodeWidth + paddingRight , graph .getWidth (), DOUBLE_EQ_EPSILON );
102102 assertEquals (paddingTop + nodeHeight + nodeNodeSpacing + nodeHeight + paddingBottom , graph .getHeight (), DOUBLE_EQ_EPSILON );
103103 }
104+
105+ /**
106+ * Tests that the graph size is correct when the graph consists of disconnected components.
107+ */
108+ @ Test
109+ public void ComponentsGraphSizeCalculationTest () {
110+ PlainJavaInitialization .initializePlainJavaLayout ();
111+ ElkNode graph = ElkGraphUtil .createGraph ();
112+ graph .setProperty (CoreOptions .ALGORITHM , MrTreeOptions .ALGORITHM_ID );
113+ graph .setProperty (CoreOptions .PADDING , new ElkPadding (0 ));
114+ graph .setProperty (CoreOptions .SPACING_NODE_NODE , 0.0 );
115+ // set aspect ratio to high value to force components to be laid out horizontally for the test
116+ graph .setProperty (CoreOptions .ASPECT_RATIO , 1000.0 );
117+
118+
119+ ElkNode n1 = ElkGraphUtil .createNode (graph );
120+ n1 .setDimensions (nodeWidth , nodeHeight );
121+ ElkNode n2 = ElkGraphUtil .createNode (graph );
122+ n2 .setDimensions (nodeWidth , nodeHeight );
123+
124+
125+ // prepare layout engine
126+ LayoutConfigurator config = new LayoutConfigurator ();
127+ ElkUtil .applyVisitors (graph , config , new LayoutAlgorithmResolver ());
128+ // call layout with layout engine
129+ try {
130+ new RecursiveGraphLayoutEngine ().layout (graph , new BasicProgressMonitor ());
131+ } catch (UnsupportedGraphException exception ) {
132+ fail (exception .toString ());
133+ }
134+
135+ assertEquals (nodeWidth + nodeWidth , graph .getWidth (), DOUBLE_EQ_EPSILON );
136+ assertEquals (nodeHeight , graph .getHeight (), DOUBLE_EQ_EPSILON );
137+ }
104138}
0 commit comments