use of org.eclipse.elk.core.options.Direction in project elk by eclipse.
the class OneDimensionalCompactor method changeDirection.
/**
* Changes the direction for compaction by transforming the hitboxes.
*
* @param dir
* the new direction
* @return
* this instance of {@link OneDimensionalCompactor}
*/
public OneDimensionalCompactor changeDirection(final Direction dir) {
if (finished) {
throw new IllegalStateException("The " + getClass().getSimpleName() + " instance has been finished already.");
}
// segments would interchange
if (!cGraph.supports(dir)) {
throw new RuntimeException("The direction " + dir + " is not supported by the CGraph instance.");
}
// short-circuit if nothing todo
if (dir == direction) {
return this;
}
Direction oldDirection = direction;
direction = dir;
// being recalculated and CNodes are locked
switch(oldDirection) {
case UNDEFINED:
switch(dir) {
case LEFT:
calculateConstraints();
break;
case RIGHT:
mirrorHitboxes();
calculateConstraints();
break;
case UP:
transposeHitboxes();
calculateConstraints();
break;
case DOWN:
transposeHitboxes();
mirrorHitboxes();
calculateConstraints();
break;
default:
break;
}
break;
case LEFT:
switch(dir) {
case RIGHT:
mirrorHitboxes();
reverseConstraints();
break;
case UP:
transposeHitboxes();
calculateConstraints();
break;
case DOWN:
transposeHitboxes();
mirrorHitboxes();
calculateConstraints();
break;
default:
break;
}
break;
case RIGHT:
switch(dir) {
case LEFT:
mirrorHitboxes();
reverseConstraints();
break;
case UP:
mirrorHitboxes();
transposeHitboxes();
calculateConstraints();
break;
case DOWN:
mirrorHitboxes();
transposeHitboxes();
mirrorHitboxes();
calculateConstraints();
break;
default:
break;
}
break;
case UP:
switch(dir) {
case LEFT:
transposeHitboxes();
calculateConstraints();
break;
case RIGHT:
transposeHitboxes();
mirrorHitboxes();
calculateConstraints();
break;
case DOWN:
mirrorHitboxes();
reverseConstraints();
break;
default:
break;
}
break;
case DOWN:
switch(dir) {
case LEFT:
mirrorHitboxes();
transposeHitboxes();
calculateConstraints();
break;
case RIGHT:
mirrorHitboxes();
transposeHitboxes();
mirrorHitboxes();
calculateConstraints();
break;
case UP:
mirrorHitboxes();
reverseConstraints();
break;
default:
break;
}
break;
default:
break;
}
return this;
}
use of org.eclipse.elk.core.options.Direction in project elk by eclipse.
the class OneDimensionalCompactorTest method testSubsequentDirectionsCompaction.
/* --------------------------------------------------
* Testing subsequent calls with different directions
* -------------------------------------------------- */
@Test
public void testSubsequentDirectionsCompaction() {
CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
CNode one = CNode.of().hitbox(new ElkRectangle(0, 0, 20, 20)).create(graph);
CNode two = CNode.of().hitbox(new ElkRectangle(25, 0, 20, 20)).create(graph);
CNode three = CNode.of().hitbox(new ElkRectangle(0, 25, 20, 20)).create(graph);
CNode four = CNode.of().hitbox(new ElkRectangle(25, 25, 20, 20)).create(graph);
Set<Direction> directions = EnumSet.of(Direction.LEFT, Direction.RIGHT, Direction.UP, Direction.DOWN);
// subsequently apply all combinations of four subsequent compaction steps
for (Direction d1 : directions) {
for (Direction d2 : directions) {
for (Direction d3 : directions) {
for (Direction d4 : directions) {
compacter(graph).setSpacingsHandler(TEST_SPACING_HANDLER).changeDirection(d1).compact().changeDirection(d2).compact().changeDirection(d3).compact().changeDirection(d4).compact().finish();
// the way we modeled the graph, every node should stay where it is
String currentDirections = d1 + " " + d2 + " " + d3 + " " + d4;
assertEquals(currentDirections, 0, one.hitbox.x, EPSILON);
assertEquals(currentDirections, 0, one.hitbox.y, EPSILON);
assertEquals(currentDirections, 25, two.hitbox.x, EPSILON);
assertEquals(currentDirections, 0, two.hitbox.y, EPSILON);
assertEquals(currentDirections, 0, three.hitbox.x, EPSILON);
assertEquals(currentDirections, 25, three.hitbox.y, EPSILON);
assertEquals(currentDirections, 25, four.hitbox.x, EPSILON);
assertEquals(currentDirections, 25, four.hitbox.y, EPSILON);
}
}
}
}
}
use of org.eclipse.elk.core.options.Direction in project elk by eclipse.
the class LGraphToCGraphTransformer method init.
private void init() {
// checking if the graph has edges and possibly prohibiting vertical compaction
boolean hasEdges = false;
int index = 0;
for (Layer l : layeredGraph) {
l.id = index++;
for (LNode n : l) {
// avoid calling Iterables.isEmpty unnecessarily
if (!hasEdges && !Iterables.isEmpty(n.getConnectedEdges())) {
hasEdges = true;
}
}
}
EnumSet<Direction> supportedDirections = EnumSet.of(Direction.UNDEFINED, Direction.LEFT, Direction.RIGHT);
if (!hasEdges) {
supportedDirections.add(Direction.UP);
supportedDirections.add(Direction.DOWN);
}
// initializing members
cGraph = new CGraph(supportedDirections);
nodesMap.clear();
commentOffsets.clear();
lockMap.clear();
verticalSegmentsMap.clear();
}
use of org.eclipse.elk.core.options.Direction in project elk by eclipse.
the class ElkUtil method resizeNode.
/**
* Sets the size of a given node, depending on the minimal size, the number of ports
* on each side and the label.
*
* @param node the node that shall be resized
* @return a vector holding the width and height resizing ratio, or {@code null} if the size
* constraint is set to {@code FIXED}
*/
public static KVector resizeNode(final ElkNode node) {
Set<SizeConstraint> sizeConstraint = node.getProperty(CoreOptions.NODE_SIZE_CONSTRAINTS);
if (sizeConstraint.isEmpty()) {
return null;
}
double newWidth = 0, newHeight = 0;
if (sizeConstraint.contains(SizeConstraint.PORTS)) {
PortConstraints portConstraints = node.getProperty(CoreOptions.PORT_CONSTRAINTS);
double minNorth = 2, minEast = 2, minSouth = 2, minWest = 2;
Direction direction = node.getParent() == null ? node.getProperty(CoreOptions.DIRECTION) : node.getParent().getProperty(CoreOptions.DIRECTION);
for (ElkPort port : node.getPorts()) {
PortSide portSide = port.getProperty(CoreOptions.PORT_SIDE);
if (portSide == PortSide.UNDEFINED) {
portSide = calcPortSide(port, direction);
port.setProperty(CoreOptions.PORT_SIDE, portSide);
}
if (portConstraints == PortConstraints.FIXED_POS) {
switch(portSide) {
case NORTH:
minNorth = Math.max(minNorth, port.getX() + port.getWidth());
break;
case EAST:
minEast = Math.max(minEast, port.getY() + port.getHeight());
break;
case SOUTH:
minSouth = Math.max(minSouth, port.getX() + port.getWidth());
break;
case WEST:
minWest = Math.max(minWest, port.getY() + port.getHeight());
break;
}
} else {
switch(portSide) {
case NORTH:
minNorth += port.getWidth() + 2;
break;
case EAST:
minEast += port.getHeight() + 2;
break;
case SOUTH:
minSouth += port.getWidth() + 2;
break;
case WEST:
minWest += port.getHeight() + 2;
break;
}
}
}
newWidth = Math.max(minNorth, minSouth);
newHeight = Math.max(minEast, minWest);
}
return resizeNode(node, newWidth, newHeight, true, true);
}
use of org.eclipse.elk.core.options.Direction in project elk by eclipse.
the class DotExporter method transformEdges.
/**
* Transform the edges of the given parent node.
*
* @param parent a parent node
* @param statements the list to which new statements are added
* @param transData transformation data
*/
private void transformEdges(final ElkNode parent, final List<Statement> statements, final IDotTransformationData<ElkNode, GraphvizModel> transData) {
boolean hierarchy = transData.getProperty(HIERARCHY);
boolean transformEdgeLayout = transData.getProperty(TRANSFORM_EDGE_LAYOUT);
Direction direction = parent.getProperty(CoreOptions.DIRECTION);
boolean vertical = direction == Direction.DOWN || direction == Direction.UP || direction == Direction.UNDEFINED;
LinkedList<ElkNode> nodes = new LinkedList<>(parent.getChildren());
BiMap<ElkGraphElement, String> nodeIds = transData.getProperty(GRAPH_ELEMS).inverse();
while (!nodes.isEmpty()) {
ElkNode source = nodes.removeFirst();
for (ElkEdge edge : ElkGraphUtil.allOutgoingEdges(source)) {
// We don't support hyperedges
if (edge.isHyperedge()) {
throw new UnsupportedGraphException("Hyperedges are not supported.");
}
ElkNode target = ElkGraphUtil.connectableShapeToNode(edge.getTargets().get(0));
// cross-hierarchy edges are considered only if hierarchy mode is active
if (source.getParent() == target.getParent() || hierarchy && isInsideGraph(target, transData.getSourceGraph())) {
EdgeStatement edgeStatement = DotFactory.eINSTANCE.createEdgeStatement();
List<Attribute> attributes = edgeStatement.getAttributes();
// set source node or cluster
Node sourceNode = DotFactory.eINSTANCE.createNode();
if (hierarchy && !source.getChildren().isEmpty()) {
sourceNode.setName(source.getProperty(CLUSTER_DUMMY));
attributes.add(createAttribute(Attributes.LTAIL, nodeIds.get(source)));
} else {
sourceNode.setName(nodeIds.get(source));
}
edgeStatement.setSourceNode(sourceNode);
// set target node or cluster
EdgeTarget edgeTarget = DotFactory.eINSTANCE.createEdgeTarget();
Node targetNode = DotFactory.eINSTANCE.createNode();
if (hierarchy && !target.getChildren().isEmpty()) {
targetNode.setName(target.getProperty(CLUSTER_DUMMY));
attributes.add(createAttribute(Attributes.LHEAD, nodeIds.get(target)));
} else {
targetNode.setName(nodeIds.get(target));
}
edgeTarget.setTargetnode(targetNode);
edgeStatement.getEdgeTargets().add(edgeTarget);
// add edge labels at head, tail, and middle position
setEdgeLabels(edge, attributes, vertical);
if (transData.getProperty(USE_EDGE_IDS)) {
// add comment with edge identifier
String edgeID = getEdgeID(edge, transData);
attributes.add(createAttribute(Attributes.COMMENT, "\"" + edgeID + "\""));
}
// include edge routing for full export, if there is one
if (!edge.getSections().isEmpty()) {
ElkEdgeSection edgeSection = edge.getSections().get(0);
if (transformEdgeLayout && (edgeSection.getBendPoints().size() > 0 || edgeSection.getStartX() != 0 || edgeSection.getStartY() != 0 || edgeSection.getEndX() != 0 || edgeSection.getEndY() != 0)) {
StringBuilder pos = new StringBuilder();
Iterator<KVector> pointIter = ElkUtil.createVectorChain(edgeSection).iterator();
while (pointIter.hasNext()) {
KVector point = pointIter.next();
ElkUtil.toAbsolute(point, edge.getContainingNode());
pos.append(point.x);
pos.append(",");
pos.append(point.y);
if (pointIter.hasNext()) {
pos.append(" ");
}
}
attributes.add(createAttribute(Attributes.POS, "\"" + pos + "\""));
}
}
statements.add(edgeStatement);
}
}
if (hierarchy) {
nodes.addAll(source.getChildren());
}
}
}
Aggregations