Search in sources :

Example 6 with RecursiveGraphLayoutEngine

use of org.eclipse.elk.core.RecursiveGraphLayoutEngine in project elk by eclipse.

the class RecursiveGraphLayoutEngineTest method testUnresolvedGraph.

@Test
public void testUnresolvedGraph() {
    Graph graph = new Graph();
    graph.root.setProperty(CoreOptions.ALGORITHM, "org.eclipse.elk.box");
    RecursiveGraphLayoutEngine engine = new RecursiveGraphLayoutEngine();
    engine.layout(graph.root, new BasicProgressMonitor());
    assertTrue(graph.root.getWidth() > 0);
    assertTrue(graph.root.getHeight() > 0);
}
Also used : RecursiveGraphLayoutEngine(org.eclipse.elk.core.RecursiveGraphLayoutEngine) BasicProgressMonitor(org.eclipse.elk.core.util.BasicProgressMonitor) Test(org.junit.Test)

Example 7 with RecursiveGraphLayoutEngine

use of org.eclipse.elk.core.RecursiveGraphLayoutEngine 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 RecursiveGraphLayoutEngine

use of org.eclipse.elk.core.RecursiveGraphLayoutEngine in project elk by eclipse.

the class RecursiveGraphLayoutEngineTest method testEmptyAlgorithmId.

@Test
public void testEmptyAlgorithmId() {
    Graph graph = new Graph();
    RecursiveGraphLayoutEngine engine = new RecursiveGraphLayoutEngine();
    engine.layout(graph.root, new BasicProgressMonitor());
    assertEquals("org.eclipse.elk.layered", graph.root.getProperty(CoreOptions.RESOLVED_ALGORITHM).getId());
}
Also used : RecursiveGraphLayoutEngine(org.eclipse.elk.core.RecursiveGraphLayoutEngine) BasicProgressMonitor(org.eclipse.elk.core.util.BasicProgressMonitor) Test(org.junit.Test)

Example 9 with RecursiveGraphLayoutEngine

use of org.eclipse.elk.core.RecursiveGraphLayoutEngine 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 10 with RecursiveGraphLayoutEngine

use of org.eclipse.elk.core.RecursiveGraphLayoutEngine in project elk by eclipse.

the class PlainLayoutTest method testPlainLayout.

/**
 * Test a plain Java layout on a hierarchical graph using the ELK Layered algorithm.
 */
@Test
public void testPlainLayout() {
    // create a hierarchical KGraph for layout
    ElkNode parentNode = GraphTestUtils.createHierarchicalGraph();
    // configure every hierarchical node to use ELK Layered (which would also be the default)
    getAllElkNodes(parentNode).forEachRemaining(node -> {
        if (!node.getChildren().isEmpty()) {
            node.setProperty(CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
        }
    });
    // create a progress monitor
    IElkProgressMonitor progressMonitor = new BasicProgressMonitor();
    // initialize the meta data service with ELK Layered's meta data
    LayoutMetaDataService service = LayoutMetaDataService.getInstance();
    service.registerLayoutMetaDataProviders(new LayeredOptions());
    // instantiate a recursive graph layout engine and execute layout
    RecursiveGraphLayoutEngine layoutEngine = new RecursiveGraphLayoutEngine();
    layoutEngine.layout(parentNode, progressMonitor);
    // output layout information
    printLayoutInfo(parentNode, progressMonitor);
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) BasicProgressMonitor(org.eclipse.elk.core.util.BasicProgressMonitor) RecursiveGraphLayoutEngine(org.eclipse.elk.core.RecursiveGraphLayoutEngine) LayoutMetaDataService(org.eclipse.elk.core.data.LayoutMetaDataService) Test(org.junit.Test)

Aggregations

RecursiveGraphLayoutEngine (org.eclipse.elk.core.RecursiveGraphLayoutEngine)13 BasicProgressMonitor (org.eclipse.elk.core.util.BasicProgressMonitor)10 Test (org.junit.Test)9 ElkNode (org.eclipse.elk.graph.ElkNode)7 NullElkProgressMonitor (org.eclipse.elk.core.util.NullElkProgressMonitor)3 IGraphLayoutEngine (org.eclipse.elk.core.IGraphLayoutEngine)2 LayoutMetaDataService (org.eclipse.elk.core.data.LayoutMetaDataService)2 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)2 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)2 ElkPort (org.eclipse.elk.graph.ElkPort)2 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)1 SporeMetaDataProvider (org.eclipse.elk.alg.spore.options.SporeMetaDataProvider)1 TestAlgorithm (org.eclipse.elk.alg.test.framework.algorithm.TestAlgorithm)1 LayoutConfigurator (org.eclipse.elk.core.LayoutConfigurator)1 UnsupportedConfigurationException (org.eclipse.elk.core.UnsupportedConfigurationException)1 LayoutAlgorithmData (org.eclipse.elk.core.data.LayoutAlgorithmData)1 LayoutAlgorithmResolver (org.eclipse.elk.core.data.LayoutAlgorithmResolver)1 PortSide (org.eclipse.elk.core.options.PortSide)1