Search in sources :

Example 1 with FGraph

use of org.eclipse.elk.alg.force.graph.FGraph in project elk by eclipse.

the class ForceImportTest method testImport.

// CHECKSTYLEOFF MagicNumber
/**
 * Test importing a simple graph.
 */
@Test
public void testImport() {
    FGraph fGraph = createSimpleGraph();
    checkSimpleGraph(fGraph);
}
Also used : FGraph(org.eclipse.elk.alg.force.graph.FGraph) Test(org.junit.Test)

Example 2 with FGraph

use of org.eclipse.elk.alg.force.graph.FGraph in project elk by eclipse.

the class ForceImportTest method testDoNotSeparateConnectedComponents.

/**
 * Ensure that a single {@link FGraph} is imported if connected components shall not be split.
 */
@Test
public void testDoNotSeparateConnectedComponents() {
    ComponentsProcessor cp = new ComponentsProcessor();
    FGraph graph = createTwoComponentsGraph();
    graph.setProperty(ForceOptions.SEPARATE_CONNECTED_COMPONENTS, false);
    List<FGraph> graphs = cp.split(graph);
    assertThat(graphs.size(), is(1));
    FGraph fGraph = graphs.get(0);
    assertThat(fGraph.getNodes().size(), is(6));
    assertThat(fGraph.getEdges().size(), is(4));
    assertThat(fGraph.getLabels().size(), is(4));
}
Also used : FGraph(org.eclipse.elk.alg.force.graph.FGraph) ComponentsProcessor(org.eclipse.elk.alg.force.ComponentsProcessor) Test(org.junit.Test)

Example 3 with FGraph

use of org.eclipse.elk.alg.force.graph.FGraph in project elk by eclipse.

the class ComponentsProcessor method dfs.

/**
 * Perform a DFS starting on the given node and collect all nodes that are found in the
 * corresponding connected component.
 *
 * @param node a node.
 * @param last the last node, i.e. the node from which the dfs arrived at {@value node}, or {@code null}
 *             if the dfs just started.
 * @param graph a graph representing a connected component, or {@code null}.
 * @param visited boolean indicating for each node whether it was already visited ({@code true})
 *                or not.
 * @param incidence list of incident edges for each node.
 * @return the connected component, or {@code null} if the node was already visited.
 */
private FGraph dfs(final FNode node, final FNode last, final FGraph graph, final boolean[] visited, final List<FEdge>[] incidence) {
    if (!visited[node.id]) {
        visited[node.id] = true;
        FGraph component = graph;
        if (component == null) {
            component = new FGraph();
        }
        component.getNodes().add(node);
        for (FEdge edge : incidence[node.id]) {
            if (edge.getTarget() == last || edge.getSource() == last) {
                // Do not handle again the edge we just arrived from
                continue;
            }
            if (edge.getSource() != node) {
                dfs(edge.getSource(), node, component, visited, incidence);
            }
            if (edge.getTarget() != node) {
                dfs(edge.getTarget(), node, component, visited, incidence);
            }
            component.getEdges().add(edge);
            component.getLabels().addAll(edge.getLabels());
        }
        return component;
    }
    return null;
}
Also used : FEdge(org.eclipse.elk.alg.force.graph.FEdge) FGraph(org.eclipse.elk.alg.force.graph.FGraph)

Example 4 with FGraph

use of org.eclipse.elk.alg.force.graph.FGraph in project elk by eclipse.

the class ForceLayoutProvider method layout.

@Override
public void layout(final ElkNode elkGraph, final IElkProgressMonitor progressMonitor) {
    progressMonitor.begin("ELK Force", 1);
    // if requested, compute nodes's dimensions, place node labels, ports, port labels, etc.
    if (!elkGraph.getProperty(ForceOptions.OMIT_NODE_MICRO_LAYOUT)) {
        NodeMicroLayout.forGraph(elkGraph).execute();
    }
    // transform the input graph
    IGraphImporter<ElkNode> graphImporter = new ElkGraphImporter();
    FGraph fgraph = graphImporter.importGraph(elkGraph);
    // set special properties for the layered graph
    setOptions(fgraph, elkGraph);
    // update the force model depending on user selection
    updateModel(fgraph.getProperty(ForceOptions.MODEL));
    // split the input graph into components
    List<FGraph> components = componentsProcessor.split(fgraph);
    // perform the actual layout
    for (FGraph comp : components) {
        forceModel.layout(comp, progressMonitor.subTask(1.0f / components.size()));
    }
    // pack the components back into one graph
    fgraph = componentsProcessor.recombine(components);
    // apply the layout results to the original graph
    graphImporter.applyLayout(fgraph);
    progressMonitor.done();
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) FGraph(org.eclipse.elk.alg.force.graph.FGraph)

Example 5 with FGraph

use of org.eclipse.elk.alg.force.graph.FGraph in project elk by eclipse.

the class ForceImportTest method testSeparateConnectedComponents.

/**
 * Ensure that connected components are split when desired.
 *
 * Also verifies that the split graphs have the correct number of nodes, edges, and labels.
 */
@Test
public void testSeparateConnectedComponents() {
    ComponentsProcessor cp = new ComponentsProcessor();
    FGraph graph = createTwoComponentsGraph();
    graph.setProperty(ForceOptions.SEPARATE_CONNECTED_COMPONENTS, true);
    List<FGraph> graphs = cp.split(graph);
    assertThat(graphs.size(), is(2));
    graphs.forEach(g -> checkSimpleGraph(g));
}
Also used : FGraph(org.eclipse.elk.alg.force.graph.FGraph) ComponentsProcessor(org.eclipse.elk.alg.force.ComponentsProcessor) Test(org.junit.Test)

Aggregations

FGraph (org.eclipse.elk.alg.force.graph.FGraph)9 FNode (org.eclipse.elk.alg.force.graph.FNode)3 ElkNode (org.eclipse.elk.graph.ElkNode)3 Test (org.junit.Test)3 ComponentsProcessor (org.eclipse.elk.alg.force.ComponentsProcessor)2 FBendpoint (org.eclipse.elk.alg.force.graph.FBendpoint)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ElkGraphImporter (org.eclipse.elk.alg.force.ElkGraphImporter)1 ForceLayoutProvider (org.eclipse.elk.alg.force.ForceLayoutProvider)1 FEdge (org.eclipse.elk.alg.force.graph.FEdge)1 KVector (org.eclipse.elk.core.math.KVector)1