Search in sources :

Example 6 with LayoutAlgorithmData

use of org.eclipse.elk.core.data.LayoutAlgorithmData 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)

Example 7 with LayoutAlgorithmData

use of org.eclipse.elk.core.data.LayoutAlgorithmData in project elk by eclipse.

the class RecursiveGraphLayoutEngineTest method testResolvedGraph.

@Test
public void testResolvedGraph() {
    Graph graph = new Graph();
    LayoutAlgorithmData algorithmData = LayoutMetaDataService.getInstance().getAlgorithmData("org.eclipse.elk.box");
    graph.root.setProperty(CoreOptions.RESOLVED_ALGORITHM, algorithmData);
    RecursiveGraphLayoutEngine engine = new RecursiveGraphLayoutEngine();
    engine.layout(graph.root, new BasicProgressMonitor());
    assertTrue(graph.root.getWidth() > 0);
    assertTrue(graph.root.getHeight() > 0);
}
Also used : LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) RecursiveGraphLayoutEngine(org.eclipse.elk.core.RecursiveGraphLayoutEngine) BasicProgressMonitor(org.eclipse.elk.core.util.BasicProgressMonitor) Test(org.junit.Test)

Example 8 with LayoutAlgorithmData

use of org.eclipse.elk.core.data.LayoutAlgorithmData in project elk by eclipse.

the class TestAlgorithm method fromTestClass.

/**
 * Loads the test layout algorithms defined in the test class.
 *
 * @param testClass
 *            the test class.
 * @param errors
 *            list of error conditions encountered while evaluating the layout algorithms.
 * @return a list of layout algorithms to use during the test.
 */
public static List<TestAlgorithm> fromTestClass(final TestClass testClass, final List<Throwable> errors) {
    List<LayoutAlgorithmData> algorithmData = new ArrayList<>();
    // Obtain annotations
    Algorithm[] algorithmAnnotations = testClass.getJavaClass().getAnnotationsByType(Algorithm.class);
    AllAlgorithms allAlgorithmsAnnotation = testClass.getAnnotation(AllAlgorithms.class);
    LayoutMetaDataService service = LayoutMetaDataService.getInstance();
    if (algorithmAnnotations.length != 0 && allAlgorithmsAnnotation != null) {
        // Only one of the two may be specified
        errors.add(new Exception("If @AllAlgorithms is specified, @Algorithm cannot be used anymore."));
    } else if (allAlgorithmsAnnotation != null) {
        // Simply add all known algorithm IDs
        algorithmData.addAll(service.getAlgorithmData());
    } else {
        // Add all specifically supplied IDs as long as they refer to known layout algorithms
        for (Algorithm algAnnotation : algorithmAnnotations) {
            LayoutAlgorithmData algData = service.getAlgorithmData(algAnnotation.value());
            if (algData != null) {
                algorithmData.add(algData);
            } else {
                errors.add(new Exception("Unknown layout algorithm: " + algAnnotation.value()));
            }
        }
    }
    // Produce the list of algorithms
    List<TestAlgorithm> algorithms = new ArrayList<>();
    algorithmData.stream().sorted((data1, data2) -> data1.getId().compareTo(data2.getId())).map(algData -> new TestAlgorithm(algData)).forEach(strategy -> algorithms.add(strategy));
    return algorithms;
}
Also used : AllAlgorithms(org.eclipse.elk.alg.test.framework.annotations.AllAlgorithms) CoreOptions(org.eclipse.elk.core.options.CoreOptions) ElkUtil(org.eclipse.elk.core.util.ElkUtil) List(java.util.List) LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator) TestClass(org.junit.runners.model.TestClass) Algorithm(org.eclipse.elk.alg.test.framework.annotations.Algorithm) LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) ElkNode(org.eclipse.elk.graph.ElkNode) LayoutMetaDataService(org.eclipse.elk.core.data.LayoutMetaDataService) ArrayList(java.util.ArrayList) LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) ArrayList(java.util.ArrayList) AllAlgorithms(org.eclipse.elk.alg.test.framework.annotations.AllAlgorithms) Algorithm(org.eclipse.elk.alg.test.framework.annotations.Algorithm) LayoutMetaDataService(org.eclipse.elk.core.data.LayoutMetaDataService)

Example 9 with LayoutAlgorithmData

use of org.eclipse.elk.core.data.LayoutAlgorithmData in project elk by eclipse.

the class LayoutConfigurationManager method getSupportedOptions.

/**
 * Determine a list of options supported by the layout algorithms from the given configuration store.
 *
 * @param config a layout configuration store associated to a graph element
 * @return a list of supported options
 */
public Set<LayoutOptionData> getSupportedOptions(final ILayoutConfigurationStore config) {
    LayoutMetaDataService layoutDataService = LayoutMetaDataService.getInstance();
    Set<LayoutOptionData> optionData = new LinkedHashSet<LayoutOptionData>();
    Set<LayoutOptionData.Target> optionTargets = config.getOptionTargets();
    if (optionTargets.contains(LayoutOptionData.Target.PARENTS)) {
        LayoutAlgorithmData algoData = getAlgorithm(config);
        if (algoData != null) {
            optionData.addAll(layoutDataService.getOptionData(algoData, LayoutOptionData.Target.PARENTS));
        }
    }
    ILayoutConfigurationStore parentConfig = config.getParent();
    if (parentConfig != null) {
        LayoutAlgorithmData algoData = getAlgorithm(parentConfig);
        if (algoData != null) {
            for (LayoutOptionData.Target target : optionTargets) {
                if (target != LayoutOptionData.Target.PARENTS) {
                    optionData.addAll(layoutDataService.getOptionData(algoData, target));
                }
            }
        }
    }
    return optionData;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) LayoutOptionData(org.eclipse.elk.core.data.LayoutOptionData) LayoutMetaDataService(org.eclipse.elk.core.data.LayoutMetaDataService)

Example 10 with LayoutAlgorithmData

use of org.eclipse.elk.core.data.LayoutAlgorithmData in project elk by eclipse.

the class LayoutConfigurationManager method isFullHierarchyLayout.

/**
 * Determine whether the given configuration store is set up to do a full-hierarchy layout,
 * i.e. to process all contained hierarchy levels with a single layout algorithm invocation.
 */
protected boolean isFullHierarchyLayout(final ILayoutConfigurationStore config) {
    Object layoutHierarchyVal = config.getOptionValue(CoreOptions.HIERARCHY_HANDLING.getId());
    HierarchyHandling layoutHierarchy = layoutHierarchyVal instanceof HierarchyHandling ? (HierarchyHandling) layoutHierarchyVal : HierarchyHandling.valueOf((String) layoutHierarchyVal);
    if (layoutHierarchy == HierarchyHandling.INCLUDE_CHILDREN) {
        LayoutAlgorithmData algoData = getAlgorithm(config);
        return algoData != null && (algoData.supportsFeature(GraphFeature.COMPOUND) || algoData.supportsFeature(GraphFeature.CLUSTERS));
    }
    return false;
}
Also used : LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) HierarchyHandling(org.eclipse.elk.core.options.HierarchyHandling)

Aggregations

LayoutAlgorithmData (org.eclipse.elk.core.data.LayoutAlgorithmData)16 ElkNode (org.eclipse.elk.graph.ElkNode)5 AbstractLayoutProvider (org.eclipse.elk.core.AbstractLayoutProvider)4 LayoutMetaDataService (org.eclipse.elk.core.data.LayoutMetaDataService)4 List (java.util.List)2 Graph (org.eclipse.elk.alg.spore.graph.Graph)2 LayoutCategoryData (org.eclipse.elk.core.data.LayoutCategoryData)2 ElkUtil (org.eclipse.elk.core.util.ElkUtil)2 ElkBendPoint (org.eclipse.elk.graph.ElkBendPoint)2 Sets (com.google.common.collect.Sets)1 ArrayList (java.util.ArrayList)1 EnumSet (java.util.EnumSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 TEdge (org.eclipse.elk.alg.common.TEdge)1 IOverlapHandler (org.eclipse.elk.alg.common.spore.IOverlapHandler)1 InternalProperties (org.eclipse.elk.alg.common.spore.InternalProperties)1 ScanlineOverlapCheck (org.eclipse.elk.alg.common.spore.ScanlineOverlapCheck)1 SVGImage (org.eclipse.elk.alg.common.utils.SVGImage)1 ElkGraphTransformer (org.eclipse.elk.alg.disco.transform.ElkGraphTransformer)1