Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import org.eclipse.elk.alg.mrtree.graph.TEdge;
import org.eclipse.elk.alg.mrtree.graph.TGraph;
import org.eclipse.elk.alg.mrtree.graph.TNode;
import org.eclipse.elk.alg.mrtree.intermediate.GraphBoundsProcessor;
import org.eclipse.elk.alg.mrtree.options.InternalProperties;
import org.eclipse.elk.alg.mrtree.options.MrTreeOptions;
import org.eclipse.elk.core.math.ElkPadding;
import org.eclipse.elk.core.math.KVector;
import org.eclipse.elk.core.options.CoreOptions;
import org.eclipse.elk.core.util.NullElkProgressMonitor;
import org.eclipse.elk.graph.properties.IProperty;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -258,6 +260,10 @@ public int compare(final TGraph graph1, final TGraph graph2) {
}
}

// We need to recompute the graphs bounds, since each component only knows its own bounds and the prop merge
// cannot catch this
GraphBoundsProcessor boundsProcessor = new GraphBoundsProcessor();
boundsProcessor.process(result, new NullElkProgressMonitor());
// Move the resulting graph to 0,0 and apply padding
applyPaddingAndNormalizePositions(result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,38 @@ public void GraphSizeCalculationTest() {
assertEquals(paddingLeft + nodeWidth + nodeNodeSpacing + nodeWidth + paddingRight, graph.getWidth(), DOUBLE_EQ_EPSILON);
assertEquals(paddingTop + nodeHeight + nodeNodeSpacing + nodeHeight + paddingBottom, graph.getHeight(), DOUBLE_EQ_EPSILON);
}

/**
* Tests that the graph size is correct when the graph consists of disconnected components.
*/
@Test
public void ComponentsGraphSizeCalculationTest() {
PlainJavaInitialization.initializePlainJavaLayout();
ElkNode graph = ElkGraphUtil.createGraph();
graph.setProperty(CoreOptions.ALGORITHM, MrTreeOptions.ALGORITHM_ID);
graph.setProperty(CoreOptions.PADDING, new ElkPadding(0));
graph.setProperty(CoreOptions.SPACING_NODE_NODE, 0.0);
// set aspect ratio to high value to force components to be laid out horizontally for the test
graph.setProperty(CoreOptions.ASPECT_RATIO, 1000.0);


ElkNode n1 = ElkGraphUtil.createNode(graph);
n1.setDimensions(nodeWidth, nodeHeight);
ElkNode n2 = ElkGraphUtil.createNode(graph);
n2.setDimensions(nodeWidth, nodeHeight);


// prepare layout engine
LayoutConfigurator config = new LayoutConfigurator();
ElkUtil.applyVisitors(graph, config, new LayoutAlgorithmResolver());
// call layout with layout engine
try {
new RecursiveGraphLayoutEngine().layout(graph, new BasicProgressMonitor());
} catch (UnsupportedGraphException exception) {
fail(exception.toString());
}

assertEquals(nodeWidth + nodeWidth, graph.getWidth(), DOUBLE_EQ_EPSILON);
assertEquals(nodeHeight, graph.getHeight(), DOUBLE_EQ_EPSILON);
}
}