Search in sources :

Example 1 with ElkGraphTransformer

use of org.eclipse.elk.alg.disco.transform.ElkGraphTransformer in project elk by eclipse.

the class DisCoLayoutProvider method layout.

// /////////////////////////////////////////////////////////////////////////////
// Layout
/*
     * (non-Javadoc)
     */
@Override
public void layout(final ElkNode layoutGraph, final IElkProgressMonitor progressMonitor) {
    progressMonitor.begin("Connected Components Compaction", 1);
    componentSpacing = layoutGraph.getProperty(DisCoOptions.SPACING_COMPONENT_COMPONENT);
    // If desired, apply a layout algorithm to the connected components themselves
    if (layoutGraph.hasProperty(DisCoOptions.COMPONENT_COMPACTION_COMPONENT_LAYOUT_ALGORITHM)) {
        String requestedAlgorithm = layoutGraph.getProperty(DisCoOptions.COMPONENT_COMPACTION_COMPONENT_LAYOUT_ALGORITHM);
        LayoutAlgorithmData lad = LayoutMetaDataService.getInstance().getAlgorithmDataBySuffix(requestedAlgorithm);
        if (lad != null) {
            AbstractLayoutProvider layoutProvider = lad.getInstancePool().fetch();
            layoutProvider.layout(layoutGraph, progressMonitor.subTask(1));
        }
    }
    // 1.) Transform given KGraph into DCGraph
    ElkGraphTransformer transformer = new ElkGraphTransformer(componentSpacing);
    result = transformer.importGraph(layoutGraph);
    // 2.) Choose strategy and compact the DCGraph (only polyomino compaction at the moment)
    switch(layoutGraph.getProperty(DisCoMetaDataProvider.COMPONENT_COMPACTION_STRATEGY)) {
        // components
        case POLYOMINO:
            new DisCoPolyominoCompactor().compact(result);
            // Only for debugging purposes, see org.eclipse.elk.alg.disco.debug.views.DisCoGraphRenderer
            layoutGraph.setProperty(DisCoOptions.DEBUG_DISCO_POLYS, result.getProperty(DisCoOptions.DEBUG_DISCO_POLYS));
            break;
        default:
            System.out.println("DisCo: no compaction strategy used for connected components.");
    }
    // 3.) Apply new layout to input graph
    transformer.applyLayout();
    // Only for debugging purposes, see org.eclipse.elk.alg.disco.debug.views.DisCoGraphRenderer
    layoutGraph.setProperty(DisCoOptions.DEBUG_DISCO_GRAPH, result);
    progressMonitor.done();
}
Also used : LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) ElkGraphTransformer(org.eclipse.elk.alg.disco.transform.ElkGraphTransformer) AbstractLayoutProvider(org.eclipse.elk.core.AbstractLayoutProvider)

Aggregations

ElkGraphTransformer (org.eclipse.elk.alg.disco.transform.ElkGraphTransformer)1 AbstractLayoutProvider (org.eclipse.elk.core.AbstractLayoutProvider)1 LayoutAlgorithmData (org.eclipse.elk.core.data.LayoutAlgorithmData)1