use of org.eclipse.elk.alg.layered.options.GraphCompactionStrategy in project elk by eclipse.
the class HorizontalGraphCompactor method process.
@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor progressMonitor) {
GraphCompactionStrategy strategy = layeredGraph.getProperty(LayeredOptions.COMPACTION_POST_COMPACTION_STRATEGY);
if (strategy == GraphCompactionStrategy.NONE) {
return;
}
progressMonitor.begin("Horizontal Compaction", 1);
this.lGraph = layeredGraph;
// the layered graph is transformed into a CGraph that is passed to OneDimensionalCompactor
LGraphToCGraphTransformer transformer = new LGraphToCGraphTransformer();
OneDimensionalCompactor odc = new OneDimensionalCompactor(transformer.transform(layeredGraph));
// consider special spacing requirements of the lgraph's nodes and edges
odc.setSpacingsHandler(specialSpacingsHandler);
// -
switch(layeredGraph.getProperty(LayeredOptions.COMPACTION_POST_COMPACTION_CONSTRAINTS)) {
case SCANLINE:
odc.setConstraintAlgorithm(new EdgeAwareScanlineConstraintCalculation(lGraph));
break;
default:
odc.setConstraintAlgorithm(OneDimensionalCompactor.QUADRATIC_CONSTRAINTS);
}
// -
switch(strategy) {
case LEFT:
odc.compact();
break;
case RIGHT:
odc.changeDirection(Direction.RIGHT).compact();
break;
case LEFT_RIGHT_CONSTRAINT_LOCKING:
// lock CNodes if they are not constrained
odc.compact().changeDirection(Direction.RIGHT).setLockFunction((node, dir) -> node.cGroup.outDegreeReal == 0).compact();
break;
case LEFT_RIGHT_CONNECTION_LOCKING:
// compacting left, locking all CNodes that have fewer connections to the right,
// then compacting right to shorten unnecessary long edges
odc.compact().changeDirection(Direction.RIGHT).setLockFunction((node, dir) -> transformer.getLockMap().get(node).get(dir)).compact();
break;
case EDGE_LENGTH:
odc.setCompactionAlgorithm(NETWORK_SIMPLEX_COMPACTION).compact();
break;
default:
// nobody should get here
break;
}
// since changeDirection may transform hitboxes, the final direction has to be LEFT again
odc.finish();
// applying the compacted positions to the LGraph and updating its size and offset
transformer.applyLayout();
progressMonitor.done();
}
Aggregations