Search in sources :

Example 1 with GraphCompactionStrategy

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();
}
Also used : IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) OneDimensionalCompactor(org.eclipse.elk.alg.common.compaction.oned.OneDimensionalCompactor) ISpacingsHandler(org.eclipse.elk.alg.common.compaction.oned.ISpacingsHandler) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) GraphCompactionStrategy(org.eclipse.elk.alg.layered.options.GraphCompactionStrategy) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) CNode(org.eclipse.elk.alg.common.compaction.oned.CNode) Spacings(org.eclipse.elk.alg.layered.options.Spacings) ICompactionAlgorithm(org.eclipse.elk.alg.common.compaction.oned.ICompactionAlgorithm) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Direction(org.eclipse.elk.core.options.Direction) LNode(org.eclipse.elk.alg.layered.graph.LNode) Collections(java.util.Collections) NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) GraphCompactionStrategy(org.eclipse.elk.alg.layered.options.GraphCompactionStrategy) OneDimensionalCompactor(org.eclipse.elk.alg.common.compaction.oned.OneDimensionalCompactor)

Aggregations

Collections (java.util.Collections)1 CNode (org.eclipse.elk.alg.common.compaction.oned.CNode)1 ICompactionAlgorithm (org.eclipse.elk.alg.common.compaction.oned.ICompactionAlgorithm)1 ISpacingsHandler (org.eclipse.elk.alg.common.compaction.oned.ISpacingsHandler)1 OneDimensionalCompactor (org.eclipse.elk.alg.common.compaction.oned.OneDimensionalCompactor)1 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)1 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)1 LNode (org.eclipse.elk.alg.layered.graph.LNode)1 NodeType (org.eclipse.elk.alg.layered.graph.LNode.NodeType)1 GraphCompactionStrategy (org.eclipse.elk.alg.layered.options.GraphCompactionStrategy)1 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)1 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)1 Spacings (org.eclipse.elk.alg.layered.options.Spacings)1 ILayoutProcessor (org.eclipse.elk.core.alg.ILayoutProcessor)1 Direction (org.eclipse.elk.core.options.Direction)1 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)1