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