use of org.eclipse.elk.alg.layered.graph.LNode in project elk by eclipse.
the class HierarchicalNodeResizingProcessor method process.
@Override
public void process(final LGraph graph, final IElkProgressMonitor progressMonitor) {
progressMonitor.begin("Resize child graph to fit parent.", 1);
for (Layer layer : graph) {
graph.getLayerlessNodes().addAll(layer.getNodes());
layer.getNodes().clear();
}
for (LNode node : graph.getLayerlessNodes()) {
node.setLayer(null);
}
graph.getLayers().clear();
resizeGraph(graph);
if (isNested(graph)) {
graphLayoutToNode(graph.getParentNode(), graph);
}
progressMonitor.done();
}
use of org.eclipse.elk.alg.layered.graph.LNode in project elk by eclipse.
the class HierarchicalNodeResizingProcessor method resizeGraphNoReallyIMeanIt.
/**
* Applies a new effective size to a graph that previously had an old size calculated by the layout algorithm. This
* method takes care of adjusting content alignments as well as external ports that would be misplaced if the new
* size is larger than the old one.
*
* @param lgraph
* the graph to apply the size to.
* @param oldSize
* old size as calculated by the layout algorithm.
* @param newSize
* new size that may be larger than the old one.
*/
private void resizeGraphNoReallyIMeanIt(final LGraph lgraph, final KVector oldSize, final KVector newSize) {
// obey to specified alignment constraints
Set<ContentAlignment> contentAlignment = lgraph.getProperty(LayeredOptions.CONTENT_ALIGNMENT);
// horizontal alignment
if (newSize.x > oldSize.x) {
if (contentAlignment.contains(ContentAlignment.H_CENTER)) {
lgraph.getOffset().x += (newSize.x - oldSize.x) / 2f;
} else if (contentAlignment.contains(ContentAlignment.H_RIGHT)) {
lgraph.getOffset().x += newSize.x - oldSize.x;
}
}
// vertical alignment
if (newSize.y > oldSize.y) {
if (contentAlignment.contains(ContentAlignment.V_CENTER)) {
lgraph.getOffset().y += (newSize.y - oldSize.y) / 2f;
} else if (contentAlignment.contains(ContentAlignment.V_BOTTOM)) {
lgraph.getOffset().y += newSize.y - oldSize.y;
}
}
// correct the position of eastern and southern hierarchical ports, if necessary
if (lgraph.getProperty(InternalProperties.GRAPH_PROPERTIES).contains(GraphProperties.EXTERNAL_PORTS) && (newSize.x > oldSize.x || newSize.y > oldSize.y)) {
// (at this point, the graph's nodes are not divided into layers anymore)
for (LNode node : lgraph.getLayerlessNodes()) {
// we're only looking for external port dummies
if (node.getType() == NodeType.EXTERNAL_PORT) {
// check which side the external port is on
PortSide extPortSide = node.getProperty(InternalProperties.EXT_PORT_SIDE);
if (extPortSide == PortSide.EAST) {
node.getPosition().x += newSize.x - oldSize.x;
} else if (extPortSide == PortSide.SOUTH) {
node.getPosition().y += newSize.y - oldSize.y;
}
}
}
}
// Actually apply the new size
LPadding padding = lgraph.getPadding();
lgraph.getSize().x = newSize.x - padding.left - padding.right;
lgraph.getSize().y = newSize.y - padding.top - padding.bottom;
}
use of org.eclipse.elk.alg.layered.graph.LNode in project elk by eclipse.
the class EndLabelSorterTest method testNode.
private void testNode(final LNode node) {
switch(node.getType()) {
case NORMAL:
// Build a list of label strings that we can check
if (node.hasProperty(InternalProperties.END_LABELS)) {
for (LabelCell labelCell : node.getProperty(InternalProperties.END_LABELS).values()) {
List<String> labelStrings = labelCell.getLabels().stream().map(label -> label.getText()).collect(Collectors.toList());
failIfUnsorted(labelStrings);
}
}
break;
case LABEL:
List<LLabel> labels = node.getProperty(InternalProperties.REPRESENTED_LABELS);
assertNotNull(labels);
List<String> labelStrings = labels.stream().map(label -> label.getText()).collect(Collectors.toList());
failIfUnsorted(labelStrings);
break;
}
}
use of org.eclipse.elk.alg.layered.graph.LNode in project elk by eclipse.
the class InLayerConstraintProcessorTest method testValidNodeOrder.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
@TestAfterProcessor(InLayerConstraintProcessor.class)
public void testValidNodeOrder(final Object graph) {
LGraph lGraph = (LGraph) graph;
for (Layer layer : lGraph) {
InLayerConstraint lastConstraint = null;
for (LNode node : layer) {
InLayerConstraint currentConstraint = node.getProperty(InternalProperties.IN_LAYER_CONSTRAINT);
if (lastConstraint != null && currentConstraint != lastConstraint) {
// if the value changes check valid transitions
String error = "Invalid constraint transition: " + lastConstraint.name() + " -> " + currentConstraint.name();
if (currentConstraint == InLayerConstraint.NONE) {
assertTrue(error, lastConstraint == InLayerConstraint.TOP);
} else if (currentConstraint == InLayerConstraint.BOTTOM) {
assertTrue(error, lastConstraint == InLayerConstraint.TOP || lastConstraint == InLayerConstraint.NONE);
}
lastConstraint = currentConstraint;
}
lastConstraint = currentConstraint;
}
}
}
use of org.eclipse.elk.alg.layered.graph.LNode in project elk by eclipse.
the class TestGraphCreator method getNodesInDifferentLayoutUnitsPreventSwitch.
/**
* <pre>
* * <-- this ...
* /
* *-+-* <-- cannot switch with this
* / _|__
* * | |
* |__|
*
* .
* </pre>
*
* @return graph of the form above.
*/
public LGraph getNodesInDifferentLayoutUnitsPreventSwitch() {
Layer[] layers = makeLayers(2);
LNode[] leftNodes = addNodesToLayer(2, layers[0]);
LNode[] rightNodes = addNodesToLayer(3, layers[1]);
eastWestEdgeFromTo(leftNodes[0], rightNodes[1]);
eastWestEdgeFromTo(leftNodes[1], rightNodes[0]);
LPort southPort = addPortOnSide(rightNodes[1], PortSide.SOUTH);
LPort northPort = addPortOnSide(rightNodes[2], PortSide.NORTH);
addEdgeBetweenPorts(southPort, northPort);
rightNodes[1].setProperty(InternalProperties.IN_LAYER_LAYOUT_UNIT, rightNodes[2]);
rightNodes[2].setProperty(InternalProperties.IN_LAYER_LAYOUT_UNIT, rightNodes[2]);
setUpIds();
return graph;
}
Aggregations