Java Code Examples for edu.uci.ics.jung.algorithms.layout.Layout#getGraph()
The following examples show how to use
edu.uci.ics.jung.algorithms.layout.Layout#getGraph() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArticulatedEdgeRouter.java From ghidra with Apache License 2.0 | 6 votes |
private Map<V, Rectangle> getVertexBounds() { if (cachedVertexBoundsMap != null) { return cachedVertexBoundsMap; } Layout<V, E> layout = viewer.getGraphLayout(); Graph<V, E> graph = layout.getGraph(); Collection<V> vertices = graph.getVertices(); Map<V, Rectangle> map = new HashMap<>(); for (V v : vertices) { Rectangle vertexBounds = getVertexBoundsInGraphSpace(viewer, v); map.put(v, vertexBounds); } cachedVertexBoundsMap = map; return map; }
Example 2
Source File: BasicEdgeRouter.java From ghidra with Apache License 2.0 | 6 votes |
protected boolean isOccluded(E edge, Shape graphSpaceShape) { Layout<V, E> layout = viewer.getGraphLayout(); Graph<V, E> graph = layout.getGraph(); Collection<V> vertices = graph.getVertices(); for (V vertex : vertices) { Rectangle vertexBounds = getVertexBoundsInGraphSpace(viewer, vertex); Pair<V> endpoints = graph.getEndpoints(edge); if (vertex == endpoints.getFirst() || vertex == endpoints.getSecond()) { // do we ever care if an edge is occluded by its own vertices? continue; } if (graphSpaceShape.intersects(vertexBounds)) { return true; } } return false; }
Example 3
Source File: GroupedFunctionGraphVertex.java From ghidra with Apache License 2.0 | 6 votes |
private Map<FGVertex, Point2D> getCurrentVertexLocations() { FGController fgController = getController(); FGView view = fgController.getView(); VisualizationViewer<FGVertex, FGEdge> viewer = view.getPrimaryGraphViewer(); Layout<FGVertex, FGEdge> graphLayout = viewer.getGraphLayout(); Graph<FGVertex, FGEdge> graph = graphLayout.getGraph(); Collection<FGVertex> currentVertices = graph.getVertices(); Map<FGVertex, Point2D> map = new HashMap<>(); for (FGVertex vertex : currentVertices) { if (vertex == this) { // not sure if we need to do this, but, conceptually, we are getting the locations // in the graph before this group node is installed continue; } Point2D point2D = graphLayout.apply(vertex); map.put(vertex, new Point((int) point2D.getX(), (int) point2D.getY())); } return map; }
Example 4
Source File: ArticulatedEdgeRouter.java From ghidra with Apache License 2.0 | 5 votes |
/** * Returns a mapping edges to vertices that touch them. * * @param viewer the viewer containing the graph * @param edgeCollection the edges to check for occlusion * @return a mapping of occluded edges (a subset of the provided edges) to those vertices that * occlude them. */ private Map<E, Set<V>> getOccludedEdges(Collection<E> edgeCollection) { Layout<V, E> layout = viewer.getGraphLayout(); Graph<V, E> graph = layout.getGraph(); Set<V> prototype = new HashSet<>(); Factory<Set<V>> factory = FactoryUtils.prototypeFactory(prototype); Map<E, Set<V>> map = MapUtils.lazyMap(new HashMap<E, Set<V>>(), factory); Map<V, Rectangle> vertexBoundsMap = getVertexBounds(); Set<Entry<V, Rectangle>> entrySet = vertexBoundsMap.entrySet(); for (Entry<V, Rectangle> entry : entrySet) { V v = entry.getKey(); Rectangle vertexBounds = getVertexBoundsInGraphSpace(viewer, v); for (E edge : edgeCollection) { Shape edgeShape = getEdgeShapeInGraphSpace(viewer, edge); Pair<V> endpoints = graph.getEndpoints(edge); if (v == endpoints.getFirst() || v == endpoints.getSecond()) { // do we ever care if an edge is occluded by its own vertices? continue; } if (edgeShape.intersects(vertexBounds)) { Set<V> set = map.get(edge); set.add(v); } } } return map; }
Example 5
Source File: VisualGraphPickingGraphMousePlugin.java From ghidra with Apache License 2.0 | 5 votes |
private void updatedArticulatedEdges(GraphViewer<V, E> viewer, V v) { Layout<V, E> layout = viewer.getGraphLayout(); Graph<V, E> graph = layout.getGraph(); Collection<E> edges = graph.getIncidentEdges(v); VisualGraphViewUpdater<V, E> updater = getViewUpdater(viewer); updater.updateEdgeShapes(edges); }
Example 6
Source File: VisualGraphEdgeSelectionGraphMousePlugin.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void mouseClicked(MouseEvent e) { if (!isHandlingMouseEvents) { return; } E edgeReference = selectedEdge; // grab a copy before we reset our state e.consume(); resetState(); // on double-clicks we go to the vertex in the current edge direction unless that vertex // is already selected, then we go to the other vertex GraphViewer<V, E> viewer = getGraphViewer(e); PickedState<V> pickedVertexState = viewer.getPickedVertexState(); Layout<V, E> layout = viewer.getGraphLayout(); Graph<V, E> graph = layout.getGraph(); V destination = graph.getDest(edgeReference); if (!pickedVertexState.isPicked(destination)) { pickAndShowVertex(destination, pickedVertexState, viewer); return; } // the destination was picked, go the other direction V source = graph.getSource(edgeReference); pickAndShowVertex(source, pickedVertexState, viewer); }
Example 7
Source File: VisualVertexRenderer.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void paintVertex(RenderContext<V, E> rc, Layout<V, E> layout, V vertex) { Graph<V, E> graph = layout.getGraph(); if (!rc.getVertexIncludePredicate().apply( Context.<Graph<V, E>, V> getInstance(graph, vertex))) { return; } GraphicsDecorator g = rc.getGraphicsContext(); GraphicsDecorator gCopy = getEmphasisGraphics(g, vertex, rc, layout); // Note: for most graphs, the full/compact shapes are the same Shape fullShape = getFullShape(rc, layout, vertex); Shape compactShape = getCompactShape(rc, layout, vertex); if (!vertexHit(rc, fullShape)) { return; } Rectangle bounds = fullShape.getBounds(); paintHighlight(rc, vertex, gCopy, bounds); paintDropShadow(rc, gCopy, compactShape, vertex); paintVertexOrVertexShape(rc, gCopy, layout, vertex, compactShape, fullShape); gCopy.dispose(); }
Example 8
Source File: TreeModelNodeRenderer.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
@Override public void paintVertex(RenderContext<V, E> rc, Layout<V, E> layout, V v) { Graph<V, E> graph = layout.getGraph(); if (rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V> getInstance(graph, v))) { paintIconForVertex(rc, v, layout); } }
Example 9
Source File: DiagramGenerator.java From incubator-batchee with Apache License 2.0 | 5 votes |
public void labelEdge(final RenderContext<Node, Edge> rc, final Layout<Node, Edge> layout, final Edge e, final String label) { if (label == null || label.length() == 0) { return; } final Graph<Node, Edge> graph = layout.getGraph(); // don't draw edge if either incident vertex is not drawn final Pair<Node> endpoints = graph.getEndpoints(e); final Node v1 = endpoints.getFirst(); final Node v2 = endpoints.getSecond(); if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Edge>getInstance(graph, e))) { return; } if (!rc.getVertexIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Node>getInstance(graph, v1)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Node>getInstance(graph, v2))) { return; } final Point2D p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v1)); final Point2D p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v2)); final GraphicsDecorator g = rc.getGraphicsContext(); final Component component = prepareRenderer(rc, rc.getEdgeLabelRenderer(), label, rc.getPickedEdgeState().isPicked(e), e); final Dimension d = component.getPreferredSize(); final AffineTransform old = g.getTransform(); final AffineTransform xform = new AffineTransform(old); final FontMetrics fm = g.getFontMetrics(); int w = fm.stringWidth(e.text); double p = Math.max(0, p1.getX() + p2.getX() - w); xform.translate(Math.min(layout.getSize().width - w, p / 2), (p1.getY() + p2.getY() - fm.getHeight()) / 2); g.setTransform(xform); g.draw(component, rc.getRendererPane(), 0, 0, d.width, d.height, true); g.setTransform(old); }
Example 10
Source File: ArticulatedEdgeRouter.java From ghidra with Apache License 2.0 | 4 votes |
private void moveArticulationsAroundVertices(Set<V> vertices, E edge, boolean goLeft) { Layout<V, E> layout = viewer.getGraphLayout(); Graph<V, E> graph = layout.getGraph(); Pair<V> endpoints = graph.getEndpoints(edge); V start = endpoints.getFirst(); V end = endpoints.getSecond(); Point2D startPoint = layout.apply(start); Point2D endPoint = layout.apply(end); // Rectangle bounds = getBoundsForVerticesInLayoutSpace(viewer, vertices); // paint the shape // Color color = getIntersectingBoxColor(edge); // String name = goLeft ? "Left" : "Right"; // DebugShape<V, E> debugShape = // new DebugShape<V, E>(viewer, debugCounter, name, // translateShapeFromLayoutSpaceToGraphSpace(bounds, viewer), color); // viewer.addPostRenderPaintable(debugShape); Rectangle bounds = spaceBetweenEndPointsShape.getBounds(); int padding = 20; int x = goLeft ? bounds.x : bounds.x + bounds.width; x += goLeft ? -padding : padding; Point2D top = new Point2D.Double(x, bounds.y - padding); Point2D bottom = new Point2D.Double(x, bounds.y + bounds.height + padding); if (startPoint.getY() > endPoint.getY()) { // swap the top and bottom points, as our source vertex is below the destination Point2D newTop = bottom; bottom = top; top = newTop; } List<Point2D> articulationPoints = new ArrayList<>(); articulationPoints.add(top); articulationPoints.add(bottom); edge.setArticulationPoints(articulationPoints); }
Example 11
Source File: BasicEdgeRouter.java From ghidra with Apache License 2.0 | 4 votes |
protected List<Point2D> removeBadlyAngledArticulations(E edge, List<Point2D> articulations) { Layout<V, E> layout = viewer.getGraphLayout(); Graph<V, E> graph = layout.getGraph(); Pair<V> endpoints = graph.getEndpoints(edge); V start = endpoints.getFirst(); V end = endpoints.getSecond(); Point2D startPoint = layout.apply(start); Point2D endPoint = layout.apply(end); if (startPoint.getY() > endPoint.getY()) { // swap the top and bottom points, as our source vertex is below the destination Point2D newStart = endPoint; endPoint = startPoint; startPoint = newStart; } List<Point2D> newList = new ArrayList<>(); for (Point2D articulation : articulations) { double deltaY = articulation.getY() - startPoint.getY(); double deltaX = articulation.getX() - startPoint.getX(); double theta = Math.atan2(deltaY, deltaX); double degrees = theta * 180 / Math.PI; if (degrees < 0 || degrees > 180) { continue; } deltaY = endPoint.getY() - articulation.getY(); deltaX = endPoint.getX() - articulation.getX(); theta = Math.atan2(deltaY, deltaX); degrees = theta * 180 / Math.PI; if (degrees < 0 || degrees > 180) { continue; } newList.add(articulation); } return newList; }
Example 12
Source File: TreeModelEdgeLabelRenderer.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
@Override public void labelEdge(RenderContext<V, E> rc, Layout<V, E> layout, E e, String label) { if (label == null || label.length() == 0) { return; } Graph<V, E> graph = layout.getGraph(); // don't draw edge if either incident vertex is not drawn Pair<V> endpoints = graph.getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); if (!rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V> getInstance(graph, v1)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V> getInstance(graph, v2))) { return; } Point2D p1 = layout.transform(v1); Point2D p2 = layout.transform(v2); p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p1); p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p2); float x1 = (float) p1.getX(); float y1 = (float) p1.getY(); float x2 = (float) p2.getX(); float y2 = (float) p2.getY(); GraphicsDecorator g = rc.getGraphicsContext(); float distX = x2 - x1; float distY = y2 - y1; double totalLength = Math.sqrt(distX * distX + distY * distY); double closeness = rc.getEdgeLabelClosenessTransformer().transform(Context.<Graph<V, E>, E> getInstance(graph, e)) .doubleValue(); int posX = (int) (x1 + closeness * distX); int posY = (int) (y1 + closeness * distY); int xDisplacement = 0; int yDisplacement = 0; xDisplacement = (int) (rc.getLabelOffset() * (distX / totalLength)); yDisplacement = (int) (rc.getLabelOffset() * (-distY / totalLength)); AffineTransform old = g.getTransform(); AffineTransform xform = new AffineTransform(old); xform.translate(posX + xDisplacement, posY + yDisplacement); double parallelOffset = 0.0d; Component component = prepareRenderer(rc, rc.getEdgeLabelRenderer(), label, rc.getPickedEdgeState().isPicked(e), e); Dimension d = component.getPreferredSize(); xform.translate(-d.width / 2.0d, -(d.height / 2.0d - parallelOffset)); g.setTransform(xform); g.setColor(Colors.WHITE); g.draw(component, rc.getRendererPane(), 0, 0, d.width, d.height, true); g.setTransform(old); }
Example 13
Source File: TreeModelNodeLabelRenderer.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
/** * Labels the specified vertex with the specified label. Uses the font specified by this * instance's <code>VertexFontFunction</code>. (If the font is unspecified, the existing font * for the graphics context is used.) If vertex label centering is active, the label is centered * on the position of the vertex; otherwise the label is offset slightly. */ @Override public void labelVertex(RenderContext<V, E> rc, Layout<V, E> layout, V v, String label) { Graph<V, E> graph = layout.getGraph(); if (rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V> getInstance(graph, v)) == false) { return; } Point2D pt = layout.transform(v); pt = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, pt); float x = (float) pt.getX(); float y = (float) pt.getY(); Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), label, rc.getPickedVertexState().isPicked(v), v); GraphicsDecorator g = rc.getGraphicsContext(); Dimension d = component.getPreferredSize(); AffineTransform xform = AffineTransform.getTranslateInstance(x, y); Shape shape = rc.getVertexShapeTransformer().transform(v); shape = xform.createTransformedShape(shape); if (rc.getGraphicsContext() instanceof TransformingGraphics) { BidirectionalTransformer transformer = ((TransformingGraphics) rc.getGraphicsContext()).getTransformer(); if (transformer instanceof ShapeTransformer) { ShapeTransformer shapeTransformer = (ShapeTransformer) transformer; shape = shapeTransformer.transform(shape); } } Rectangle2D bounds = shape.getBounds2D(); Point p = null; if (position == Position.AUTO) { Dimension vvd = rc.getScreenDevice().getSize(); if (vvd.width == 0 || vvd.height == 0) { vvd = rc.getScreenDevice().getPreferredSize(); } p = getAnchorPoint(bounds, d, positioner.getPosition(x, y, vvd)); } else { p = getAnchorPoint(bounds, d, position); } if (graphCreator.isLeaf((String) v) && !graphCreator.getModel().getRoot().isNumerical()) { // shift the label if there is a frequency bar p.setLocation(p.x, p.y + LEAF_LABEL_OFFSET_Y); } g.draw(component, rc.getRendererPane(), p.x, p.y, d.width, d.height, true); }