use of org.eclipse.elk.alg.layered.compaction.oned.CNode 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.alg.layered.compaction.oned.CNode 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.alg.layered.compaction.oned.CNode 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);
}
}
}
use of org.eclipse.elk.alg.layered.compaction.oned.CNode in project elk by eclipse.
the class ScanlineConstraintCalculator method sweep.
/**
* Executes a single sweep of the scanline, using {@link CNode}s that fulfill
* <code>filterFun</code>.
*
* @param filterFun
* a predicate determining for a node n whether it should be included
* @param spacingFun
* a function returning a spacing value s for a node n.
*/
protected void sweep(final Predicate<CNode> filterFun, final Function<CNode, Double> spacingFun) {
blowUpHitboxes(filterFun, spacingFun);
// add all nodes twice (once for the lower, once for the upper border)
List<Timestamp> points = Lists.newArrayList();
for (CNode n : compactor.cGraph.cNodes) {
if (filterFun.apply(n)) {
points.add(new Timestamp(n, true));
points.add(new Timestamp(n, false));
}
}
// reset internal state
constraintsScanlineHandler.reset();
// execute the scanline
Scanline.execute(points, constraintsScanlineComparator, constraintsScanlineHandler);
normalizeHitboxes(filterFun, spacingFun);
}
use of org.eclipse.elk.alg.layered.compaction.oned.CNode in project elk by eclipse.
the class LongestPathCompaction method compact.
@Override
public void compact(final OneDimensionalCompactor compactor) {
// calculating the left-most position of any element
// this will be our starting point for the compaction
double minStartPos = Double.POSITIVE_INFINITY;
for (CNode cNode : compactor.cGraph.cNodes) {
minStartPos = Math.min(minStartPos, cNode.cGroup.reference.hitbox.x + cNode.cGroupOffset.x);
}
// finding the sinks of the constraint graph
Queue<CGroup> sinks = Lists.newLinkedList();
for (CGroup group : compactor.cGraph.cGroups) {
group.startPos = minStartPos;
if (group.outDegree == 0) {
sinks.add(group);
}
}
// process sinks until every node in the constraint graph was handled
while (!sinks.isEmpty()) {
CGroup group = sinks.poll();
// record the movement of this group during the current compaction
// this has to be recorded _before_ the nodes' positions are updated
// and care has to be taken about the compaction direction. In certain
// scenarios nodes may move "back-and-forth". To detect this, we associate
// a negative delta with two of the compaction directions.
double diff = group.reference.hitbox.x;
// ------------------------------------------
for (CNode node : group.cNodes) {
// CNodes can be locked in place to avoid pulling clusters apart
double suggestedX = group.startPos + node.cGroupOffset.x;
if (// node.reposition
node.cGroup.reposition || // does the "fixed" position violate the constraints?
(node.getPosition() < suggestedX)) {
node.startPos = suggestedX;
} else {
// leave the node where it was!
node.startPos = node.hitbox.x;
}
}
diff -= group.reference.startPos;
group.delta += diff;
if (compactor.direction == Direction.RIGHT || compactor.direction == Direction.DOWN) {
group.deltaNormalized += diff;
} else {
group.deltaNormalized -= diff;
}
// ---------------------------------------------------
for (CNode node : group.cNodes) {
for (CNode incNode : node.constraints) {
// determine the required spacing
double spacing;
if (compactor.direction.isHorizontal()) {
spacing = compactor.spacingsHandler.getHorizontalSpacing(node, incNode);
} else {
spacing = compactor.spacingsHandler.getVerticalSpacing(node, incNode);
}
incNode.cGroup.startPos = Math.max(incNode.cGroup.startPos, node.startPos + node.hitbox.width + spacing - // respect the other group's node's offset
incNode.cGroupOffset.x);
// whether the node's current position should be preserved
if (!incNode.reposition) {
incNode.cGroup.startPos = Math.max(incNode.cGroup.startPos, incNode.getPosition() - incNode.cGroupOffset.x);
}
incNode.cGroup.outDegree--;
if (incNode.cGroup.outDegree == 0) {
sinks.add(incNode.cGroup);
}
}
}
}
// ------------------------------------------------------
for (CNode cNode : compactor.cGraph.cNodes) {
cNode.applyPosition();
}
}
Aggregations