use of org.eclipse.elk.alg.layered.graph.Layer in project elk by eclipse.
the class GraphTransformer method process.
@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
monitor.begin("Graph transformation (" + mode + ")", 1);
// We need to add all layerless nodes as well as all nodes in layers since this processor
// is run twice -- once before layering, and once afterwards
List<LNode> nodes = Lists.newArrayList(layeredGraph.getLayerlessNodes());
for (Layer layer : layeredGraph.getLayers()) {
nodes.addAll(layer.getNodes());
}
// graph transformations for unusual layout directions
DirectionCongruency congruency = layeredGraph.getProperty(LayeredOptions.DIRECTION_CONGRUENCY);
if (congruency == DirectionCongruency.READING_DIRECTION) {
// --------------------------------------------------------------
switch(layeredGraph.getProperty(LayeredOptions.DIRECTION)) {
case LEFT:
mirrorAllX(layeredGraph, nodes);
break;
case DOWN:
transposeAll(layeredGraph, nodes);
break;
case UP:
if (mode == Mode.TO_INTERNAL_LTR) {
transposeAll(layeredGraph, nodes);
mirrorAllY(layeredGraph, nodes);
} else {
mirrorAllY(layeredGraph, nodes);
transposeAll(layeredGraph, nodes);
}
break;
}
} else {
if (mode == Mode.TO_INTERNAL_LTR) {
// --------------------------------------------------------------
switch(layeredGraph.getProperty(LayeredOptions.DIRECTION)) {
case LEFT:
mirrorAllX(layeredGraph, nodes);
mirrorAllY(layeredGraph, nodes);
break;
case DOWN:
rotate90Clockwise(layeredGraph, nodes);
break;
case UP:
rotate90CounterClockwise(layeredGraph, nodes);
break;
}
} else {
// --------------------------------------------------------------
switch(layeredGraph.getProperty(LayeredOptions.DIRECTION)) {
case LEFT:
mirrorAllX(layeredGraph, nodes);
mirrorAllY(layeredGraph, nodes);
break;
case DOWN:
rotate90CounterClockwise(layeredGraph, nodes);
break;
case UP:
rotate90Clockwise(layeredGraph, nodes);
break;
}
}
}
monitor.done();
}
use of org.eclipse.elk.alg.layered.graph.Layer 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.Layer 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.Layer 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;
}
use of org.eclipse.elk.alg.layered.graph.Layer in project elk by eclipse.
the class TestGraphCreator method getCurrentOrder.
/**
* Returns the nodes in the graph as two-dimensional array of LNodes.
*
* @return graph as LNode[][].
*/
public LNode[][] getCurrentOrder() {
LNode[][] nodeOrder = new LNode[graph.getLayers().size()][];
List<Layer> layers = graph.getLayers();
for (int i = 0; i < layers.size(); i++) {
Layer layer = layers.get(i);
List<LNode> nodes = layer.getNodes();
nodeOrder[i] = new LNode[nodes.size()];
for (int j = 0; j < nodes.size(); j++) {
nodeOrder[i][j] = nodes.get(j);
}
}
return nodeOrder;
}
Aggregations