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;
}
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();
}
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);
}
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;
}
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;
}
Aggregations