use of org.eclipse.elk.core.options.Direction in project elk by eclipse.
the class InteractiveLayeredGraphVisitor method setCoordinates.
/**
* Sets the coordinates of the nodes in the graph {@code root} according to the set constraints.
*
* @param root
* The root of the graph that should be layouted.
*/
private void setCoordinates(final ElkNode root) {
List<List<ElkNode>> layers = calcLayerNodes(root.getChildren());
Direction direction = root.getProperty(LayeredOptions.DIRECTION);
setCoordinateInLayoutDirection(layers, direction);
int layerId = 0;
for (List<ElkNode> layer : layers) {
if (layer.size() > 0) {
setCoordinatesOrthogonalToLayoutDirection(layer, layerId, direction);
layerId++;
}
}
return;
}
use of org.eclipse.elk.core.options.Direction in project elk by eclipse.
the class OneDimensionalComponentsCompaction method updatePlaceholders.
private void updatePlaceholders(final Dir dir) {
Set<Direction> dirs = (dir == Dir.VERT) ? UP_DOWN : LEFT_RIGHT;
for (Direction d : dirs) {
for (Pair<CGroup, CNode> pair : transformer.getExternalPlaceholder().get(d)) {
CNode cNode = pair.getSecond();
CGroup parentComponentGroup = pair.getFirst();
// deltaNormalized is negative if a group was moved to the left,
// positive if the group was moved to the right
// the size of each component stays the same!
double adelta = parentComponentGroup.deltaNormalized;
switch(d) {
case LEFT:
case RIGHT:
cNode.hitbox.y += adelta;
break;
case UP:
case DOWN:
// y sticks to the top of the diagram
cNode.hitbox.x += adelta;
break;
}
}
}
}
use of org.eclipse.elk.core.options.Direction in project elk by eclipse.
the class OneDimensionalComponentsCompaction method addPlaceholders.
private void addPlaceholders(final Dir dir) {
Set<Direction> dirs = (dir == Dir.VERT) ? UP_DOWN : LEFT_RIGHT;
for (Direction d : dirs) {
for (Pair<CGroup, CNode> pair : transformer.getExternalPlaceholder().get(d)) {
compactionGraph.cNodes.add(pair.getSecond());
compactionGraph.cGroups.add(pair.getSecond().cGroup);
}
}
}
use of org.eclipse.elk.core.options.Direction in project elk by eclipse.
the class OneDimensionalComponentsCompaction method compact.
/**
* Internal compaction method, performs 3 compactions into each direction (horizontal first,
* then vertical). The first compaction is unconstrained, the latter two consider the node locks.
*/
private double compact(final int run) {
double delta = 0;
// reset all groups' deltas
for (CGroup g : compactionGraph.cGroups) {
g.delta = 0;
g.deltaNormalized = 0;
}
// ----------------------------------------------------
// #1 We want to perform horizontal compaction first.
// For this we have to add the vertical external
// edges to the hulls to prevent edge node overlaps
// ----------------------------------------------------
addPlaceholders(Dir.HORZ);
addExternalEdgeRepresentations(verticalExternalExtensions);
compactor.calculateGroupOffsets();
// there are new nodes in the compaction graph, we have to update the constraints
compactor.forceConstraintsRecalculation();
Direction direction = Direction.LEFT;
// compact horizontally
compactor.changeDirection(direction).compact().changeDirection(direction.opposite()).applyLockingStrategy().compact().changeDirection(direction).applyLockingStrategy().compact();
// very important to transform back to LEFT
// because the hitboxes representing external edges
// that will be added in a second have not been transformed yet
compactor.changeDirection(Direction.LEFT);
// remove the vertical external edges again
removeExternalEdgeRepresentations(verticalExternalExtensions);
removePlaceholders(Dir.HORZ);
// .. and offset the horizontal external edges (that will be added next)
// according to the just finished horizontal compaction
updateExternalExtensionDimensions(Dir.HORZ);
updatePlaceholders(Dir.VERT);
// ----------------------------------------------------
// #2 We want to perform vertical compaction.
// ----------------------------------------------------
// now add them
addPlaceholders(Dir.VERT);
addExternalEdgeRepresentations(horizontalExternalExtensions);
compactor.calculateGroupOffsets();
// remember delta from horizontal compaction
for (CGroup g : compactionGraph.cGroups) {
delta += Math.abs(g.deltaNormalized);
}
// reset all groups' deltas
for (CGroup g : compactionGraph.cGroups) {
g.delta = 0;
g.deltaNormalized = 0;
}
direction = Direction.UP;
// compact vertically
compactor.changeDirection(direction).forceConstraintsRecalculation().compact().changeDirection(direction.opposite()).applyLockingStrategy().compact().changeDirection(direction).applyLockingStrategy().compact();
// transform back to LEFT
compactor.changeDirection(Direction.LEFT);
// remove the horizontal external edges
removeExternalEdgeRepresentations(horizontalExternalExtensions);
removePlaceholders(Dir.VERT);
// ... offset the vertical external edges
// (which have been excluded during the last compaction)
updateExternalExtensionDimensions(Dir.VERT);
updatePlaceholders(Dir.HORZ);
compactor.forceConstraintsRecalculation();
// ... and the delta from vertical compaction
for (CGroup g : compactionGraph.cGroups) {
delta += Math.abs(g.deltaNormalized);
}
return delta;
}
use of org.eclipse.elk.core.options.Direction in project elk by eclipse.
the class OneDimensionalComponentsCompaction method removePlaceholders.
private void removePlaceholders(final Dir dir) {
Set<Direction> dirs = (dir == Dir.VERT) ? UP_DOWN : LEFT_RIGHT;
for (Direction d : dirs) {
for (Pair<CGroup, CNode> pair : transformer.getExternalPlaceholder().get(d)) {
compactionGraph.cNodes.remove(pair.getSecond());
compactionGraph.cGroups.remove(pair.getSecond().cGroup);
}
}
}
Aggregations