use of org.eclipse.elk.alg.layered.compaction.oned.CGroup in project elk by eclipse.
the class CompactionTest method testDownGroupCompaction.
/**
* The connection indicates a grouping, not an edge.
*
* +--+
* | |
* +--+-----+--+
* | |
* +--+ +--+
* | |
* +--+
*/
@Test
public void testDownGroupCompaction() {
CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
CTestNode upperLeft = new CTestNode(new ElkRectangle(0, 0, 20, 20));
graph.cNodes.add(upperLeft);
CTestNode lowerLeft = new CTestNode(new ElkRectangle(5, 40, 10, 20));
graph.cNodes.add(lowerLeft);
CTestNode right = new CTestNode(new ElkRectangle(25, 10, 20, 20));
graph.cNodes.add(right);
CGroup group = new CGroup(upperLeft, right);
graph.cGroups.add(group);
compacter(graph).changeDirection(Direction.DOWN).compact().finish();
assertEquals(15, upperLeft.hitbox.y, EPSILON);
assertEquals(40, lowerLeft.hitbox.y, EPSILON);
assertEquals(25, right.hitbox.y, EPSILON);
}
use of org.eclipse.elk.alg.layered.compaction.oned.CGroup in project elk by eclipse.
the class CompactionTest method testRightGroupCompaction.
/**
* The connection indicates a grouping, not an edge.
*
* +--+
* | | +--+
* +--+ | |
* | +--+
* |
* +--+
* | |
* +--+
*/
@Test
public void testRightGroupCompaction() {
CGraph graph = new CGraph(EnumSet.allOf(Direction.class));
CTestNode left = new CTestNode(new ElkRectangle(0, 5, 20, 20));
graph.cNodes.add(left);
CTestNode upperRight = new CTestNode(new ElkRectangle(40, 0, 20, 20));
graph.cNodes.add(upperRight);
CTestNode lowerRight = new CTestNode(new ElkRectangle(10, 25, 20, 20));
graph.cNodes.add(lowerRight);
CGroup group = new CGroup(left, lowerRight);
graph.cGroups.add(group);
compacter(graph).changeDirection(Direction.RIGHT).compact().finish();
assertEquals(15, left.hitbox.x, EPSILON);
assertEquals(40, upperRight.hitbox.x, EPSILON);
assertEquals(25, lowerRight.hitbox.x, EPSILON);
}
use of org.eclipse.elk.alg.layered.compaction.oned.CGroup in project elk by eclipse.
the class ComponentsToCGraphTransformer method transform.
/* -----------------------------------------------------------
* Graph Transformation
* ----------------------------------------------------------- */
@Override
public CGraph transform(final IConnectedComponents<N, E> ccs) {
cGraph = new CGraph(EnumSet.allOf(Direction.class));
for (IComponent<N, E> comp : ccs.getComponents()) {
CGroup group = new CGroup();
cGraph.cGroups.add(group);
// convert the hull of the graph's elements without external edges
for (ElkRectangle rect : comp.getHull()) {
CRectNode rectNode = new CRectNode(rect);
setLock(rectNode, comp.getExternalExtensionSides());
if (!oldPosition.containsKey(comp)) {
oldPosition.put(comp, new KVector(rect.x, rect.y));
offsets.put(comp, rectNode);
}
cGraph.cNodes.add(rectNode);
group.addCNode(rectNode);
}
// they can be added to the CGraph on demand later on
for (IExternalExtension<E> ee : comp.getExternalExtensions()) {
CRectNode rectNode = new CRectNode(ee.getRepresentor());
externalExtensions.put(ee, Pair.of(group, rectNode));
setLock(rectNode, comp.getExternalExtensionSides());
// placeholder
if (ee.getPlaceholder() != null) {
CRectNode rectPlaceholder = new CRectNode(ee.getPlaceholder(), 1d);
setLock(rectPlaceholder, comp.getExternalExtensionSides());
CGroup dummyGroup = new CGroup();
dummyGroup.addCNode(rectPlaceholder);
externalPlaceholder.put(ee.getDirection(), Pair.of(group, rectPlaceholder));
}
}
}
return cGraph;
}
use of org.eclipse.elk.alg.layered.compaction.oned.CGroup 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.CGroup 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);
}
}
}
Aggregations