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