use of org.eclipse.elk.alg.layered.options.LayerConstraint in project elk by eclipse.
the class GraphTransformer method transposeLayerConstraint.
/**
* The layer constraint and in-layer constraint set on a node. A node with layer constraint
* {@link LayerConstraint#FIRST_SEPARATE} will end up with an in-layer constraint
* {@link InLayerConstraint#TOP}. This is only meant for external port dummy nodes and only
* supports the cases that can occur with them.
*
* @param node the node whose layer constraint to mirror.
*/
private void transposeLayerConstraint(final LNode node) {
LayerConstraint layerConstraint = node.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
InLayerConstraint inLayerConstraint = node.getProperty(InternalProperties.IN_LAYER_CONSTRAINT);
if (layerConstraint == LayerConstraint.FIRST_SEPARATE) {
node.setProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.NONE);
node.setProperty(InternalProperties.IN_LAYER_CONSTRAINT, InLayerConstraint.TOP);
} else if (layerConstraint == LayerConstraint.LAST_SEPARATE) {
node.setProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.NONE);
node.setProperty(InternalProperties.IN_LAYER_CONSTRAINT, InLayerConstraint.BOTTOM);
} else if (inLayerConstraint == InLayerConstraint.TOP) {
node.setProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.FIRST_SEPARATE);
node.setProperty(InternalProperties.IN_LAYER_CONSTRAINT, InLayerConstraint.NONE);
} else if (inLayerConstraint == InLayerConstraint.BOTTOM) {
node.setProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.LAST_SEPARATE);
node.setProperty(InternalProperties.IN_LAYER_CONSTRAINT, InLayerConstraint.NONE);
}
}
use of org.eclipse.elk.alg.layered.options.LayerConstraint in project elk by eclipse.
the class InteractiveExternalPortPositioner method process.
@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor progressMonitor) {
// if the graph does not contain any external ports ...
if (!layeredGraph.getProperty(InternalProperties.GRAPH_PROPERTIES).contains(GraphProperties.EXTERNAL_PORTS)) {
// ... nothing we can do about it
return;
}
// find the minimum and maximum x coordinates of the graph
for (LNode node : layeredGraph.getLayerlessNodes()) {
if (node.getType() == NodeType.NORMAL) {
ElkMargin margins = node.getProperty(LayeredOptions.MARGINS);
minX = Math.min(minX, node.getPosition().x - margins.left);
maxX = Math.max(maxX, node.getPosition().x + node.getSize().x + margins.right);
minY = Math.min(minY, node.getPosition().y - margins.top);
maxY = Math.max(maxY, node.getPosition().y + node.getSize().y + margins.bottom);
}
}
// assign reasonable coordinates to external port dummies
for (LNode node : layeredGraph.getLayerlessNodes()) {
if (node.getType() != NodeType.NORMAL) {
switch(node.getType()) {
// SUPPRESS CHECKSTYLE NEXT 50 InnerAssignment
case EXTERNAL_PORT:
LayerConstraint lc = node.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
if (lc == LayerConstraint.FIRST_SEPARATE) {
// it's a WEST port
node.getPosition().x = minX - ARBITRARY_SPACING;
findYCoordinate(node, (e) -> e.getTarget().getNode()).transform((d) -> node.getPosition().y = d);
break;
}
if (lc == LayerConstraint.LAST_SEPARATE) {
// it's a EAST port
node.getPosition().x = maxX + ARBITRARY_SPACING;
findYCoordinate(node, (e) -> e.getSource().getNode()).transform((d) -> node.getPosition().y = d);
break;
}
InLayerConstraint ilc = node.getProperty(InternalProperties.IN_LAYER_CONSTRAINT);
if (ilc == InLayerConstraint.TOP) {
findNorthSouthPortXCoordinate(node).transform((x) -> node.getPosition().x = x + ARBITRARY_SPACING);
node.getPosition().y = minY - ARBITRARY_SPACING;
break;
}
if (ilc == InLayerConstraint.BOTTOM) {
findNorthSouthPortXCoordinate(node).transform((x) -> node.getPosition().x = x + ARBITRARY_SPACING);
node.getPosition().y = maxY + ARBITRARY_SPACING;
break;
}
break;
default:
throw new IllegalArgumentException("The node type " + node.getType() + " is not supported by the " + this.getClass());
}
}
}
}
use of org.eclipse.elk.alg.layered.options.LayerConstraint in project elk by eclipse.
the class EdgeAndLayerConstraintEdgeReverserTest method testLayerConstraints.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
@TestAfterProcessor(EdgeAndLayerConstraintEdgeReverser.class)
public void testLayerConstraints(Object graph) {
for (LNode node : ((LGraph) graph).getLayerlessNodes()) {
LayerConstraint constr = node.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
if (constr == LayerConstraint.FIRST) {
// either no incoming edges or only from FIRST_SEPARATE nodes
for (LEdge inc : node.getIncomingEdges()) {
LNode src = inc.getSource().getNode();
assertTrue(src.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT) == LayerConstraint.FIRST_SEPARATE);
}
} else if (constr == LayerConstraint.LAST) {
// either no outgoing edges or only to LAST_SEPARATE nodes
for (LEdge inc : node.getOutgoingEdges()) {
LNode src = inc.getTarget().getNode();
assertTrue(src.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT) == LayerConstraint.LAST_SEPARATE);
}
} else if (constr == LayerConstraint.FIRST_SEPARATE) {
assertTrue(Iterables.isEmpty(node.getIncomingEdges()));
} else if (constr == LayerConstraint.LAST_SEPARATE) {
assertTrue(Iterables.isEmpty(node.getOutgoingEdges()));
}
}
}
use of org.eclipse.elk.alg.layered.options.LayerConstraint in project elk by eclipse.
the class LayerConstraintProcessorTest method testLayerConstraints.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
/**
* If the first layer contains {@link LayerConstraint#FIRST_SEPARATE} no other type is allowed there. All
* {@link LayerConstraint#FIRST} constraints must be in the next layer. Similar for
* {@link LayerConstraint#LAST_SEPARATE} and {@link LayerConstraint#LAST}.
*/
@TestAfterProcessor(LayerConstraintPostprocessor.class)
public void testLayerConstraints(final Object graph) {
LGraph lGraph = (LGraph) graph;
Multimap<LayerConstraint, Integer> constraintMap = HashMultimap.create();
int nextLayerId = 0;
for (Layer layer : lGraph) {
layer.id = nextLayerId++;
for (LNode node : layer) {
constraintMap.put(node.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT), layer.id);
}
}
// if FIRST_SEPARATE nodes are available
if (constraintMap.containsKey(LayerConstraint.FIRST_SEPARATE)) {
// FIRST_SEPARATE must only occur in the first layer
Collection<Integer> firstSep = constraintMap.get(LayerConstraint.FIRST_SEPARATE);
assertTrue(firstSep.size() == 1 && firstSep.contains(0));
// first layer must not contain a NONE node
assertTrue(!constraintMap.get(LayerConstraint.NONE).contains(0));
// all FIRST nodes have to be at position 1
Collection<Integer> first = constraintMap.get(LayerConstraint.FIRST);
if (!first.isEmpty()) {
assertTrue(first.size() == 1 && first.contains(1));
}
} else {
// all FIRST nodes must be at position 0
Collection<Integer> first = constraintMap.get(LayerConstraint.FIRST);
if (!first.isEmpty()) {
assertTrue(first.size() == 1 && first.contains(0));
}
}
int lastLayer = lGraph.getLayers().size() - 1;
// if LAST_SEPARATE nodes are available
if (constraintMap.containsKey(LayerConstraint.LAST_SEPARATE)) {
// LAST_SEPARATE must only occur in the last layer
Collection<Integer> lastSep = constraintMap.get(LayerConstraint.LAST_SEPARATE);
assertTrue(lastSep.size() == 1 && lastSep.contains(lastLayer));
// last layer must not contain a NONE node
assertTrue(!constraintMap.get(LayerConstraint.NONE).contains(lastLayer));
// all LAST nodes have to be at position lastLayer - 1
Collection<Integer> last = constraintMap.get(LayerConstraint.LAST);
if (!last.isEmpty()) {
assertTrue(last.size() == 1 && last.contains(lastLayer - 1));
}
} else {
// all LAST nodes must be at position lastLayer
Collection<Integer> last = constraintMap.get(LayerConstraint.LAST);
if (!last.isEmpty()) {
assertTrue(last.size() == 1 && last.contains(lastLayer));
}
}
}
Aggregations