Search in sources :

Example 11 with LayoutAlgorithmData

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

the class AlgorithmContentProvider method applyFilter.

/**
 * Apply the current filter to the given element.
 *
 * @param element an element from the content
 * @return true if the filter admits the element
 */
public boolean applyFilter(final Object element) {
    Boolean result = filterMap.get(element);
    if (result == null) {
        if (filterValue != null && filterValue.length() > 0) {
            if (element instanceof LayoutCategoryData) {
                LayoutCategoryData typeData = (LayoutCategoryData) element;
                result = !typeData.getLayouters().isEmpty();
                if (result) {
                    String typeName = typeData.getName().toLowerCase();
                    result = typeName.contains(filterValue);
                    if (result) {
                        for (LayoutAlgorithmData layouterData : typeData.getLayouters()) {
                            filterMap.put(layouterData, Boolean.TRUE);
                        }
                        if (bestFilterMatch == null || typeName.startsWith(filterValue) && !bestFilterMatch.getName().toLowerCase().startsWith(filterValue)) {
                            bestFilterMatch = typeData;
                        }
                    } else {
                        boolean hasFilteredChild = false;
                        for (LayoutAlgorithmData layouterData : typeData.getLayouters()) {
                            hasFilteredChild |= applyFilter(layouterData);
                        }
                        result = hasFilteredChild;
                    }
                }
            } else if (element instanceof LayoutAlgorithmData) {
                LayoutAlgorithmData layouterData = (LayoutAlgorithmData) element;
                String layouterName = layouterData.getName().toLowerCase();
                if (layouterName.contains(filterValue)) {
                    result = Boolean.TRUE;
                    if (bestFilterMatch == null || layouterName.startsWith(filterValue) && !bestFilterMatch.getName().toLowerCase().startsWith(filterValue)) {
                        bestFilterMatch = layouterData;
                    }
                } else {
                    String bundle = layouterData.getBundleName();
                    result = bundle != null && bundle.toLowerCase().contains(filterValue);
                }
            }
        } else if (element instanceof LayoutCategoryData) {
            result = !((LayoutCategoryData) element).getLayouters().isEmpty();
        } else {
            result = Boolean.TRUE;
        }
        filterMap.put(element, result);
    }
    return result;
}
Also used : LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) LayoutCategoryData(org.eclipse.elk.core.data.LayoutCategoryData)

Example 12 with LayoutAlgorithmData

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

the class OverlapRemovalLayoutProvider method layout.

@Override
public void layout(final ElkNode layoutGraph, final IElkProgressMonitor progressMonitor) {
    // If desired, apply a layout algorithm
    if (layoutGraph.hasProperty(SporeCompactionOptions.UNDERLYING_LAYOUT_ALGORITHM)) {
        String requestedAlgorithm = layoutGraph.getProperty(SporeOverlapRemovalOptions.UNDERLYING_LAYOUT_ALGORITHM);
        LayoutAlgorithmData lad = LayoutMetaDataService.getInstance().getAlgorithmDataBySuffix(requestedAlgorithm);
        if (lad != null) {
            AbstractLayoutProvider layoutProvider = lad.getInstancePool().fetch();
            layoutProvider.layout(layoutGraph, progressMonitor.subTask(1));
        }
    }
    // set algorithm properties
    layoutGraph.setProperty(SporeCompactionOptions.PROCESSING_ORDER_ROOT_SELECTION, RootSelection.CENTER_NODE);
    layoutGraph.setProperty(SporeCompactionOptions.PROCESSING_ORDER_SPANNING_TREE_COST_FUNCTION, SpanningTreeCostFunction.INVERTED_OVERLAP);
    layoutGraph.setProperty(SporeCompactionOptions.PROCESSING_ORDER_TREE_CONSTRUCTION, TreeConstructionStrategy.MINIMUM_SPANNING_TREE);
    int maxIterations = layoutGraph.getProperty(SporeOverlapRemovalOptions.OVERLAP_REMOVAL_MAX_ITERATIONS);
    progressMonitor.begin("Overlap removal", 1);
    // initialize debug output
    String debugOutputFile = null;
    if (layoutGraph.getProperty(SporeOverlapRemovalOptions.DEBUG_MODE)) {
        debugOutputFile = ElkUtil.debugFolderPath("spore") + "45scanlineOverlaps";
    }
    SVGImage svg = new SVGImage(debugOutputFile);
    // set overlap handler and import ElkGraph
    Set<TEdge> overlapEdges = Sets.newHashSet();
    IOverlapHandler overlapHandler = (n1, n2) -> overlapEdges.add(new TEdge(n1.originalVertex, n2.originalVertex));
    IGraphImporter<ElkNode> graphImporter = new ElkGraphImporter();
    Graph graph = graphImporter.importGraph(layoutGraph);
    boolean overlapsExisted = true;
    int iteration = 0;
    // repeat overlap removal
    while (iteration < maxIterations && overlapsExisted) {
        // scanline overlap check
        if (layoutGraph.getProperty(SporeOverlapRemovalOptions.OVERLAP_REMOVAL_RUN_SCANLINE)) {
            overlapEdges.clear();
            new ScanlineOverlapCheck(overlapHandler, svg).sweep(graph.vertices);
            if (overlapEdges.isEmpty()) {
                // don't bother if nothing overlaps
                break;
            }
            graph.tEdges = overlapEdges;
        }
        // assembling and executing the algorithm
        algorithmAssembler.reset();
        algorithmAssembler.setPhase(SPOrEPhases.P1_STRUCTURE, StructureExtractionStrategy.DELAUNAY_TRIANGULATION);
        algorithmAssembler.setPhase(SPOrEPhases.P2_PROCESSING_ORDER, graph.treeConstructionStrategy);
        algorithmAssembler.setPhase(SPOrEPhases.P3_EXECUTION, OverlapRemovalStrategy.GROW_TREE);
        algorithm = algorithmAssembler.build(graph);
        for (ILayoutProcessor<Graph> processor : algorithm) {
            processor.process(graph, progressMonitor.subTask(1));
        }
        // update node positions
        graphImporter.updateGraph(graph);
        overlapsExisted = graph.getProperty(InternalProperties.OVERLAPS_EXISTED);
        iteration++;
    }
    // apply node positions to ElkGraph
    graphImporter.applyPositions(graph);
    progressMonitor.done();
}
Also used : TEdge(org.eclipse.elk.alg.common.TEdge) ScanlineOverlapCheck(org.eclipse.elk.alg.common.spore.ScanlineOverlapCheck) RootSelection(org.eclipse.elk.alg.spore.options.RootSelection) AlgorithmAssembler(org.eclipse.elk.core.alg.AlgorithmAssembler) AbstractLayoutProvider(org.eclipse.elk.core.AbstractLayoutProvider) LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) Set(java.util.Set) Graph(org.eclipse.elk.alg.spore.graph.Graph) TreeConstructionStrategy(org.eclipse.elk.alg.spore.options.TreeConstructionStrategy) OverlapRemovalStrategy(org.eclipse.elk.alg.spore.options.OverlapRemovalStrategy) ElkNode(org.eclipse.elk.graph.ElkNode) SpanningTreeCostFunction(org.eclipse.elk.alg.spore.options.SpanningTreeCostFunction) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) Sets(com.google.common.collect.Sets) SporeCompactionOptions(org.eclipse.elk.alg.spore.options.SporeCompactionOptions) ElkUtil(org.eclipse.elk.core.util.ElkUtil) SVGImage(org.eclipse.elk.alg.common.utils.SVGImage) List(java.util.List) SporeOverlapRemovalOptions(org.eclipse.elk.alg.spore.options.SporeOverlapRemovalOptions) IOverlapHandler(org.eclipse.elk.alg.common.spore.IOverlapHandler) StructureExtractionStrategy(org.eclipse.elk.alg.spore.options.StructureExtractionStrategy) LayoutMetaDataService(org.eclipse.elk.core.data.LayoutMetaDataService) InternalProperties(org.eclipse.elk.alg.common.spore.InternalProperties) ScanlineOverlapCheck(org.eclipse.elk.alg.common.spore.ScanlineOverlapCheck) ElkNode(org.eclipse.elk.graph.ElkNode) IOverlapHandler(org.eclipse.elk.alg.common.spore.IOverlapHandler) SVGImage(org.eclipse.elk.alg.common.utils.SVGImage) LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) TEdge(org.eclipse.elk.alg.common.TEdge) Graph(org.eclipse.elk.alg.spore.graph.Graph) AbstractLayoutProvider(org.eclipse.elk.core.AbstractLayoutProvider)

Example 13 with LayoutAlgorithmData

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

the class ShrinkTreeLayoutProvider method layout.

@Override
public void layout(final ElkNode layoutGraph, final IElkProgressMonitor progressMonitor) {
    // If desired, apply a layout algorithm
    if (layoutGraph.hasProperty(SporeCompactionOptions.UNDERLYING_LAYOUT_ALGORITHM)) {
        String requestedAlgorithm = layoutGraph.getProperty(SporeCompactionOptions.UNDERLYING_LAYOUT_ALGORITHM);
        LayoutAlgorithmData lad = LayoutMetaDataService.getInstance().getAlgorithmDataBySuffix(requestedAlgorithm);
        if (lad != null) {
            AbstractLayoutProvider layoutProvider = lad.getInstancePool().fetch();
            layoutProvider.layout(layoutGraph, progressMonitor.subTask(1));
        }
    }
    IGraphImporter<ElkNode> graphImporter = new ElkGraphImporter();
    Graph graph = graphImporter.importGraph(layoutGraph);
    shrinktree.shrink(graph, progressMonitor.subTask(1));
    graphImporter.applyPositions(graph);
}
Also used : LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) Graph(org.eclipse.elk.alg.spore.graph.Graph) ElkNode(org.eclipse.elk.graph.ElkNode) AbstractLayoutProvider(org.eclipse.elk.core.AbstractLayoutProvider)

Example 14 with LayoutAlgorithmData

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

the class LayoutPropertySource method getLayoutHint.

/**
 * Returns an identifier for a displayed layout algorithm name. The result is the identifier of
 * an algorithm whose name is a prefix of the displayed name. If there are multiple such
 * algorithms, the one with the longest prefix is taken.
 *
 * @param displayedName a displayed name of a layout algorithm
 * @return the corresponding identifier, or {@code null} if no match is found
 */
public static String getLayoutHint(final String displayedName) {
    String bestHint = null;
    int bestLength = 0;
    for (LayoutAlgorithmData layouterData : LayoutMetaDataService.getInstance().getAlgorithmData()) {
        String name = layouterData.getName();
        if (displayedName.startsWith(name) && name.length() > bestLength) {
            bestHint = layouterData.getId();
            bestLength = name.length();
        }
    }
    return bestHint;
}
Also used : LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData)

Example 15 with LayoutAlgorithmData

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

the class RecursiveGraphLayoutEngine method countNodesWithHierarchy.

/**
 * Determines the number of layout nodes in the given layout graph across multiple levels of
 * hierarchy. Counting is stopped at nodes which disable the hierarchical layout or are
 * configured to use a different layout algorithm.
 *
 * @param parentNode
 *            parent layout node to examine
 * @return total number of child layout nodes
 */
private int countNodesWithHierarchy(final ElkNode parentNode) {
    // Count the content of the given node
    int count = parentNode.getChildren().size();
    for (ElkNode childNode : parentNode.getChildren()) {
        if (childNode.getProperty(CoreOptions.HIERARCHY_HANDLING) != HierarchyHandling.SEPARATE_CHILDREN) {
            LayoutAlgorithmData parentData = parentNode.getProperty(CoreOptions.RESOLVED_ALGORITHM);
            LayoutAlgorithmData childData = childNode.getProperty(CoreOptions.RESOLVED_ALGORITHM);
            // Only count nodes that don't abort the hierarchical layout
            if ((parentData == childData || parentData != null && parentData.equals(childData)) && !childNode.getChildren().isEmpty()) {
                count += countNodesWithHierarchy(childNode);
            }
        }
    }
    return count;
}
Also used : LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) ElkNode(org.eclipse.elk.graph.ElkNode) ElkBendPoint(org.eclipse.elk.graph.ElkBendPoint)

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