private static void addPathRecursively(List<VertexRef> vertexRefs, VertexRef vertexToFind, Map<VertexRef, EdgeRef> incomingEdgeMap) { if (incomingEdgeMap.get(vertexToFind) != null) { vertexRefs.add(0, vertexToFind); addPathRecursively(vertexRefs, ((Edge) incomingEdgeMap.get(vertexToFind)).getSource().getVertex(), incomingEdgeMap); } }
Set<Vertex> collapsedSources = vertexToCollapsedVertices.get(edge.getSource().getVertex()); if (collapsedSources != null) { for (VertexRef collapsedSource : collapsedSources) { newCollapsedEdge.getSource().setVertex(collapsedSource); retval.add(newCollapsedEdge); Set<Vertex> collapsedTargets = vertexToCollapsedVertices.get(edge.getTarget().getVertex()); if (collapsedTargets != null) { for (VertexRef collapsedTarget : collapsedTargets) { newCollapsedEdge.getTarget().setVertex(collapsedTarget); retval.add(newCollapsedEdge); newCollapsedEdge.getSource().setVertex(collapsedEndpoint); newCollapsedEdge.getTarget().setVertex(collapsedTarget); retval.add(newCollapsedEdge);
private static void addPathRecursively(List<VertexRef> vertexRefs, VertexRef vertexToFind, Map<VertexRef, EdgeRef> incomingEdgeMap) { if (incomingEdgeMap.get(vertexToFind) != null) { vertexRefs.add(0, vertexToFind); addPathRecursively(vertexRefs, ((Edge) incomingEdgeMap.get(vertexToFind)).getSource().getVertex(), incomingEdgeMap); } }
Set<Vertex> collapsedSources = vertexToCollapsedVertices.get(edge.getSource().getVertex()); if (collapsedSources != null) { for (VertexRef collapsedSource : collapsedSources) { newCollapsedEdge.getSource().setVertex(collapsedSource); retval.add(newCollapsedEdge); Set<Vertex> collapsedTargets = vertexToCollapsedVertices.get(edge.getTarget().getVertex()); if (collapsedTargets != null) { for (VertexRef collapsedTarget : collapsedTargets) { newCollapsedEdge.getTarget().setVertex(collapsedTarget); retval.add(newCollapsedEdge); newCollapsedEdge.getSource().setVertex(collapsedEndpoint); newCollapsedEdge.getTarget().setVertex(collapsedTarget); retval.add(newCollapsedEdge);
private void updateLayout(Collection<Vertex> displayVertices, Collection<Edge> displayEdges) { m_displayVertices.clear(); m_displayVertices.addAll(displayVertices); m_displayEdges.clear(); m_displayEdges.addAll(displayEdges); for (Iterator<Edge> itr = m_displayEdges.iterator(); itr.hasNext();) { Edge edge = itr.next(); if (new RefComparator().compare(edge.getSource().getVertex(), edge.getTarget().getVertex()) == 0) { LOG.debug("Discarding edge whose source and target are the same: {}", edge); itr.remove(); } else if (m_displayVertices.contains(edge.getSource().getVertex())) { if (m_displayVertices.contains(edge.getTarget().getVertex())) { // This edge is OK, it is attached to two vertices that are in the graph } else { LOG.debug("Discarding edge that is not attached to 2 vertices in the graph: {}", edge); itr.remove(); } } else { LOG.debug("Discarding edge that is not attached to 2 vertices in the graph: {}", edge); itr.remove(); } } LOG.debug("Created a graph with {} vertices and {} edges", m_displayVertices.size(), m_displayEdges.size()); } }
Set<Vertex> collapsedSources = vertexToCollapsedVertices.get(edge.getSource().getVertex()); if (collapsedSources != null) { for (VertexRef collapsedSource : collapsedSources) { newCollapsedEdge.getSource().setVertex(collapsedSource); retval.add(newCollapsedEdge); Set<Vertex> collapsedTargets = vertexToCollapsedVertices.get(edge.getTarget().getVertex()); if (collapsedTargets != null) { for (VertexRef collapsedTarget : collapsedTargets) { newCollapsedEdge.getTarget().setVertex(collapsedTarget); retval.add(newCollapsedEdge); newCollapsedEdge.getSource().setVertex(collapsedEndpoint); newCollapsedEdge.getTarget().setVertex(collapsedTarget); retval.add(newCollapsedEdge);
private void updateLayout(Collection<Vertex> displayVertices, Collection<Edge> displayEdges) { m_displayVertices.clear(); m_displayVertices.addAll(displayVertices); m_displayEdges.clear(); m_displayEdges.addAll(displayEdges); for (Iterator<Edge> itr = m_displayEdges.iterator(); itr.hasNext();) { Edge edge = itr.next(); if (new RefComparator().compare(edge.getSource().getVertex(), edge.getTarget().getVertex()) == 0) { LOG.debug("Discarding edge whose source and target are the same: {}", edge); itr.remove(); } else if (m_displayVertices.contains(edge.getSource().getVertex())) { if (m_displayVertices.contains(edge.getTarget().getVertex())) { // This edge is OK, it is attached to two vertices that are in the graph } else { LOG.debug("Discarding edge that is not attached to 2 vertices in the graph: {}", edge); itr.remove(); } } else { LOG.debug("Discarding edge that is not attached to 2 vertices in the graph: {}", edge); itr.remove(); } } LOG.debug("Created a graph with {} vertices and {} edges", m_displayVertices.size(), m_displayEdges.size()); } }
@Override public final EdgeRef[] getEdgeIdsForVertex(VertexRef vertex) { if (vertex == null) return new EdgeRef[0]; List<EdgeRef> retval = new ArrayList<EdgeRef>(); for (Edge edge : getEdges()) { // If the vertex is connected to the edge then add it if (new RefComparator().compare(edge.getSource().getVertex(), vertex) == 0 || new RefComparator().compare(edge.getTarget().getVertex(), vertex) == 0) { retval.add(edge); } } return retval.toArray(new EdgeRef[0]); }
@Override public final EdgeRef[] getEdgeIdsForVertex(VertexRef vertex) { if (vertex == null) return new EdgeRef[0]; List<EdgeRef> retval = new ArrayList<EdgeRef>(); for (Edge edge : getEdges()) { // If the vertex is connected to the edge then add it if (new RefComparator().compare(edge.getSource().getVertex(), vertex) == 0 || new RefComparator().compare(edge.getTarget().getVertex(), vertex) == 0) { retval.add(edge); } } return retval.toArray(new EdgeRef[0]); }
@Override public final EdgeRef[] getEdgeIdsForVertex(VertexRef vertex) { if (vertex == null) return new EdgeRef[0]; List<EdgeRef> retval = new ArrayList<EdgeRef>(); for (Edge edge : getEdges()) { // If the vertex is connected to the edge then add it if (new RefComparator().compare(edge.getSource().getVertex(), vertex) == 0 || new RefComparator().compare(edge.getTarget().getVertex(), vertex) == 0) { retval.add(edge); } } return retval.toArray(new EdgeRef[0]); }
@Override public final Map<VertexRef, Set<EdgeRef>> getEdgeIdsForVertices(VertexRef... vertices) { List<Edge> edges = getEdges(); Map<VertexRef,Set<EdgeRef>> retval = new HashMap<VertexRef,Set<EdgeRef>>(); for (VertexRef vertex : vertices) { if (vertex == null) continue; Set<EdgeRef> edgeSet = new HashSet<EdgeRef>(); for (Edge edge : edges) { // If the vertex is connected to the edge then add it if (new RefComparator().compare(edge.getSource().getVertex(), vertex) == 0 || new RefComparator().compare(edge.getTarget().getVertex(), vertex) == 0) { edgeSet.add(edge); } } retval.put(vertex, edgeSet); } return retval; }
@Override public final Map<VertexRef, Set<EdgeRef>> getEdgeIdsForVertices(VertexRef... vertices) { List<Edge> edges = getEdges(); Map<VertexRef,Set<EdgeRef>> retval = new HashMap<VertexRef,Set<EdgeRef>>(); for (VertexRef vertex : vertices) { if (vertex == null) continue; Set<EdgeRef> edgeSet = new HashSet<EdgeRef>(); for (Edge edge : edges) { // If the vertex is connected to the edge then add it if (new RefComparator().compare(edge.getSource().getVertex(), vertex) == 0 || new RefComparator().compare(edge.getTarget().getVertex(), vertex) == 0) { edgeSet.add(edge); } } retval.put(vertex, edgeSet); } return retval; }
@Override public final Map<VertexRef, Set<EdgeRef>> getEdgeIdsForVertices(VertexRef... vertices) { List<Edge> edges = getEdges(); Map<VertexRef,Set<EdgeRef>> retval = new HashMap<VertexRef,Set<EdgeRef>>(); for (VertexRef vertex : vertices) { if (vertex == null) continue; Set<EdgeRef> edgeSet = new HashSet<EdgeRef>(); for (Edge edge : edges) { // If the vertex is connected to the edge then add it if (new RefComparator().compare(edge.getSource().getVertex(), vertex) == 0 || new RefComparator().compare(edge.getTarget().getVertex(), vertex) == 0) { edgeSet.add(edge); } } retval.put(vertex, edgeSet); } return retval; }
private edu.uci.ics.jung.graph.DirectedGraph<VertexRef, Edge> convert(final Graph g) { if (!isFullyLevelAware(g)) { throw new IllegalStateException("The graph is not LevelAware. Cannot apply Hierarchy Layout. Aborting"); } // We need to sort the elements. For this purpose we use the DirectedOrderedSparseMultigraph final edu.uci.ics.jung.graph.DirectedGraph<VertexRef, Edge> jungGraph = new DirectedOrderedSparseMultigraph<>(); final Collection<Vertex> displayVertices = g.getDisplayVertices(); // Sort by level final List<Vertex> sortedVertices = displayVertices.stream().filter(v -> v instanceof LevelAware).sorted(new Comparator<Vertex>() { @Override public int compare(Vertex o1, Vertex o2) { return Integer.compare(((LevelAware) o1).getLevel(), ((LevelAware) o2).getLevel()); } }).collect(Collectors.toList()); // Build the graph for(VertexRef v : sortedVertices) { jungGraph.addVertex(v); } // The order of edges does not matter for(Edge e : g.getDisplayEdges()) { jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex()); } return jungGraph; }
private edu.uci.ics.jung.graph.DirectedGraph<VertexRef, Edge> convert(final Graph g) { if (!isFullyLevelAware(g)) { throw new IllegalStateException("The graph is not LevelAware. Cannot apply Hierarchy Layout. Aborting"); } // We need to sort the elements. For this purpose we use the DirectedOrderedSparseMultigraph final edu.uci.ics.jung.graph.DirectedGraph<VertexRef, Edge> jungGraph = new DirectedOrderedSparseMultigraph<>(); final Collection<Vertex> displayVertices = g.getDisplayVertices(); // Sort by level final List<Vertex> sortedVertices = displayVertices.stream().filter(v -> v instanceof LevelAware).sorted(new Comparator<Vertex>() { @Override public int compare(Vertex o1, Vertex o2) { return Integer.compare(((LevelAware) o1).getLevel(), ((LevelAware) o2).getLevel()); } }).collect(Collectors.toList()); // Build the graph for(VertexRef v : sortedVertices) { jungGraph.addVertex(v); } // The order of edges does not matter for(Edge e : g.getDisplayEdges()) { jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex()); } return jungGraph; }
@Override public void updateLayout(Graph graph) { final Layout graphLayout = graph.getLayout(); SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>(); Collection<? extends Vertex> vertices = graph.getDisplayVertices(); for(Vertex v : vertices) { jungGraph.addVertex(v); } Collection<? extends Edge> edges = graph.getDisplayEdges(); for(Edge e : edges) { jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex()); } Dimension size = selectLayoutSize(graph); Dimension paddedSize = new Dimension((int)(size.getWidth()*.75), (int)(size.getHeight()*.75)); doISOMLayout(graphLayout, jungGraph, size); doSpringLayout(graphLayout, jungGraph, size, SPRING_LAYOUT_REPULSION); doFRLayout(graphLayout, jungGraph, paddedSize, (int)(size.getWidth()/8.0), (int)(size.getHeight()/8.0)); doSpringLayout(graphLayout, jungGraph, size, SPRING_LAYOUT_REPULSION); }
@Override public void updateLayout(Graph graph) { final Layout graphLayout = graph.getLayout(); SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>(); Collection<? extends Vertex> vertices = graph.getDisplayVertices(); for(Vertex v : vertices) { jungGraph.addVertex(v); } Collection<? extends Edge> edges = graph.getDisplayEdges(); for(Edge e : edges) { jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex()); } Dimension size = selectLayoutSize(graph); Dimension paddedSize = new Dimension((int)(size.getWidth()*.75), (int)(size.getHeight()*.75)); doISOMLayout(graphLayout, jungGraph, size); doSpringLayout(graphLayout, jungGraph, size, SPRING_LAYOUT_REPULSION); doFRLayout(graphLayout, jungGraph, paddedSize, (int)(size.getWidth()/8.0), (int)(size.getHeight()/8.0)); doSpringLayout(graphLayout, jungGraph, size, SPRING_LAYOUT_REPULSION); }