/** * Move the source graph into the destination graph using a specified offset. * * @param destGraph the destination graph. * @param sourceGraph the source graph. * @param offsetx x coordinate offset. * @param offsety y coordinate offset. */ private void moveGraph( final FGraph destGraph, final FGraph sourceGraph, final double offsetx, final double offsety) { KVector graphOffset = new KVector(offsetx, offsety); graphOffset.sub(sourceGraph.getProperty(Properties.BB_UPLEFT)); for (FNode node : sourceGraph.getNodes()) { node.getPosition().add(graphOffset); destGraph.getNodes().add(node); } for (FEdge edge : sourceGraph.getEdges()) { for (FBendpoint bendpoint : edge.getBendpoints()) { bendpoint.getPosition().add(graphOffset); } destGraph.getEdges().add(edge); } for (FLabel label : sourceGraph.getLabels()) { label.getPosition().add(graphOffset); destGraph.getLabels().add(label); } }
/** * Creates and returns the incidence list that for each node lists the incident edges. * * @param graph a force graph. */ @SuppressWarnings("unchecked") private List<FEdge>[] buildIncidenceLists(final FGraph graph) { int n = graph.getNodes().size(); List<FEdge>[] incidence = new List[n]; // create incidence lists for (FNode node : graph.getNodes()) { incidence[node.id] = new LinkedList<FEdge>(); } // add edges to incidence lists for (FEdge edge : graph.getEdges()) { incidence[edge.getSource().id].add(edge); incidence[edge.getTarget().id].add(edge); } return incidence; }
/** * 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 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 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.getSource() != node) { dfs(edge.getSource(), component, visited, incidence); } if (edge.getTarget() != node) { dfs(edge.getTarget(), component, visited, incidence); } component.getEdges().add(edge); component.getLabels().addAll(edge.getLabels()); } return component; } return null; }