Search in sources :

Example 1 with LayoutAlgorithmResolver

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

the class Issue562Test method test.

@Test
public void test() {
    // Create the basic graph structure
    ElkNode graph = ElkGraphUtil.createGraph();
    ElkNode n1 = ElkGraphUtil.createNode(graph);
    ElkPort p1 = ElkGraphUtil.createPort(n1);
    ElkPort p2 = ElkGraphUtil.createPort(n1);
    ElkEdge e = ElkGraphUtil.createSimpleEdge(p1, p2);
    // Create a layout configurator to apply options, just as it would happen in the DiagramLayoutEngine
    LayoutConfigurator config = new LayoutConfigurator();
    config.configure(n1).setProperty(CoreOptions.INSIDE_SELF_LOOPS_ACTIVATE, true);
    config.configure(e).setProperty(CoreOptions.INSIDE_SELF_LOOPS_YO, true);
    // Apply the configurator and a layout algorithm resolver, just like the DiagramLayoutEngine does
    ElkUtil.applyVisitors(graph, config, new LayoutAlgorithmResolver());
    // Apply layout. We don't want an UnsupportedConfigurationException to be thrown
    try {
        new RecursiveGraphLayoutEngine().layout(graph, new NullElkProgressMonitor());
    } catch (UnsupportedConfigurationException ex) {
        fail(ex.toString());
    }
}
Also used : NullElkProgressMonitor(org.eclipse.elk.core.util.NullElkProgressMonitor) ElkNode(org.eclipse.elk.graph.ElkNode) UnsupportedConfigurationException(org.eclipse.elk.core.UnsupportedConfigurationException) ElkPort(org.eclipse.elk.graph.ElkPort) RecursiveGraphLayoutEngine(org.eclipse.elk.core.RecursiveGraphLayoutEngine) LayoutAlgorithmResolver(org.eclipse.elk.core.data.LayoutAlgorithmResolver) ElkEdge(org.eclipse.elk.graph.ElkEdge) LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator) Test(org.junit.Test)

Example 2 with LayoutAlgorithmResolver

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

the class RecursiveGraphLayoutEngine method layout.

/**
 * Performs recursive layout on the given layout graph, possibly in a test setting.
 *
 * @param layoutGraph top-level node of the graph to be laid out.
 * @param testController an optional test controller if the layout run is performed as part of a unit test.
 * @param progressMonitor monitor to which progress of the layout algorithms is reported.
 */
public void layout(final ElkNode layoutGraph, final TestController testController, final IElkProgressMonitor progressMonitor) {
    int nodeCount = countNodesRecursively(layoutGraph, true);
    progressMonitor.begin("Recursive Graph Layout", nodeCount);
    ElkUtil.applyVisitors(layoutGraph, new DeprecatedLayoutOptionReplacer());
    if (!layoutGraph.hasProperty(CoreOptions.RESOLVED_ALGORITHM)) {
        // Apply the default algorithm resolver to the graph in order to obtain algorithm meta data
        ElkUtil.applyVisitors(layoutGraph, new LayoutAlgorithmResolver());
    }
    // Perform recursive layout of the whole substructure of the given node
    layoutRecursively(layoutGraph, testController, progressMonitor);
    progressMonitor.done();
}
Also used : ElkBendPoint(org.eclipse.elk.graph.ElkBendPoint) DeprecatedLayoutOptionReplacer(org.eclipse.elk.core.data.DeprecatedLayoutOptionReplacer) LayoutAlgorithmResolver(org.eclipse.elk.core.data.LayoutAlgorithmResolver)

Example 3 with LayoutAlgorithmResolver

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

the class GraphValidatorTest method testCustomValidation.

@Test
public void testCustomValidation() {
    LayoutMetaDataService.getInstance().registerLayoutMetaDataProviders(registry -> {
        registry.register(new LayoutAlgorithmData.Builder().id("foo.algorithm").providerFactory(new AlgorithmFactory(FooAlgorithm.class)).validatorClass(FooValidator.class).create());
    });
    ElkNode graph = ElkGraphUtil.createGraph();
    ElkGraphUtil.createNode(graph).setIdentifier("foo");
    graph.setProperty(CoreOptions.ALGORITHM, "foo.algorithm");
    LayoutAlgorithmResolver algorithmResolver = new LayoutAlgorithmResolver();
    GraphValidator validator = new GraphValidator();
    ElkUtil.applyVisitors(graph, algorithmResolver, validator);
    assertEquals("[ERROR: FOO! (Root Node > Node foo)]", validator.getIssues().toString());
}
Also used : LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) ElkNode(org.eclipse.elk.graph.ElkNode) AlgorithmFactory(org.eclipse.elk.core.util.AlgorithmFactory) LayoutAlgorithmResolver(org.eclipse.elk.core.data.LayoutAlgorithmResolver) GraphValidator(org.eclipse.elk.core.validation.GraphValidator) Test(org.junit.Test)

Aggregations

LayoutAlgorithmResolver (org.eclipse.elk.core.data.LayoutAlgorithmResolver)3 ElkNode (org.eclipse.elk.graph.ElkNode)2 Test (org.junit.Test)2 LayoutConfigurator (org.eclipse.elk.core.LayoutConfigurator)1 RecursiveGraphLayoutEngine (org.eclipse.elk.core.RecursiveGraphLayoutEngine)1 UnsupportedConfigurationException (org.eclipse.elk.core.UnsupportedConfigurationException)1 DeprecatedLayoutOptionReplacer (org.eclipse.elk.core.data.DeprecatedLayoutOptionReplacer)1 LayoutAlgorithmData (org.eclipse.elk.core.data.LayoutAlgorithmData)1 AlgorithmFactory (org.eclipse.elk.core.util.AlgorithmFactory)1 NullElkProgressMonitor (org.eclipse.elk.core.util.NullElkProgressMonitor)1 GraphValidator (org.eclipse.elk.core.validation.GraphValidator)1 ElkBendPoint (org.eclipse.elk.graph.ElkBendPoint)1 ElkEdge (org.eclipse.elk.graph.ElkEdge)1 ElkPort (org.eclipse.elk.graph.ElkPort)1