Class GraphViewerUtils


  • public class GraphViewerUtils
    extends java.lang.Object
    This class houses various methods for translating location and size data from the various graph coordinate spaces. Graph Spaces Size and location information is represented in multiple coordinate spaces, as listed below. To translate from one to the other, use GraphViewerUtils; for example, to see if a mouse click is on a given vertex.
    • Layout Space - the layout contains Point2D objects that represent positions of the vertices.
    • Graph Space - the space where the Layout points are transformed as the view is moved around the screen (e.g., as the user pans)
    • View Space - the coordinate system of Java 2D rendering; scaling (zooming) transformations are applied at this layer

    Note: vertex relative means that the value is from inside the vertex, or the vertex's coordinate space (like a component that is inside the vertex), where it's coordinate values are relative to the component's parent.

    • Field Detail

      • GRAPH_DECORATOR_THREAD_POOL_NAME

        public static final java.lang.String GRAPH_DECORATOR_THREAD_POOL_NAME
        See Also:
        Constant Field Values
      • GRAPH_BUILDER_THREAD_POOL_NAME

        public static final java.lang.String GRAPH_BUILDER_THREAD_POOL_NAME
        See Also:
        Constant Field Values
      • INTERACTION_ZOOM_THRESHOLD

        public static final double INTERACTION_ZOOM_THRESHOLD
        See Also:
        Constant Field Values
      • EXTRA_LAYOUT_ROW_SPACING

        public static final int EXTRA_LAYOUT_ROW_SPACING
        See Also:
        Constant Field Values
      • EXTRA_LAYOUT_ROW_SPACING_CONDENSED

        public static final int EXTRA_LAYOUT_ROW_SPACING_CONDENSED
        See Also:
        Constant Field Values
      • EXTRA_LAYOUT_COLUMN_SPACING

        public static final int EXTRA_LAYOUT_COLUMN_SPACING
        See Also:
        Constant Field Values
      • EXTRA_LAYOUT_COLUMN_SPACING_CONDENSED

        public static final int EXTRA_LAYOUT_COLUMN_SPACING_CONDENSED
        See Also:
        Constant Field Values
    • Constructor Detail

      • GraphViewerUtils

        public GraphViewerUtils()
    • Method Detail

      • translatePointFromViewSpaceToVertexRelativeSpace

        public static <V,​E> java.awt.Point translatePointFromViewSpaceToVertexRelativeSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                                  java.awt.Point startPoint)
      • translatePointFromViewSpaceToVertexRelativeSpace

        public static <V,​E> java.awt.Point translatePointFromViewSpaceToVertexRelativeSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                                  java.awt.Point startPoint,
                                                                                                  V vertex)
      • getVertexUpperLeftCornerInLayoutSpace

        public static <V,​E> java.awt.Point getVertexUpperLeftCornerInLayoutSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                       V vertex)
      • getVertexUpperLeftCornerInViewSpace

        public static <V,​E> java.awt.Point getVertexUpperLeftCornerInViewSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                     V vertex)
      • getVertexBoundsInViewSpace

        public static <V,​E> java.awt.Rectangle getVertexBoundsInViewSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                V vertex)
      • getVertexBoundsInGraphSpace

        public static <V,​E> java.awt.Rectangle getVertexBoundsInGraphSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                 V vertex)
      • getVertexBoundsInLayoutSpace

        public static <V,​E> java.awt.Rectangle getVertexBoundsInLayoutSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                  V vertex)
      • getVertexUpperLeftCornerInGraphSpace

        public static <V,​E> java.awt.Point getVertexUpperLeftCornerInGraphSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                      V vertex)
      • translatePointFromLayoutSpaceToGraphSpace

        public static <V,​E> java.awt.Point translatePointFromLayoutSpaceToGraphSpace​(java.awt.geom.Point2D pointInLayoutSpace,
                                                                                           edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer)
      • translatePointFromLayoutSpaceToViewSpace

        public static <V,​E> java.awt.Point translatePointFromLayoutSpaceToViewSpace​(java.awt.geom.Point2D pointInLayoutSpace,
                                                                                          edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer)
      • translatePointFromViewSpaceToGraphSpace

        public static <V,​E> java.awt.Point translatePointFromViewSpaceToGraphSpace​(java.awt.geom.Point2D pointInViewSpace,
                                                                                         edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer)
      • translatePointFromViewSpaceToLayoutSpace

        public static <V,​E> java.awt.Point translatePointFromViewSpaceToLayoutSpace​(java.awt.geom.Point2D pointInViewSpace,
                                                                                          edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer)
      • translatePointFromGraphSpaceToViewSpace

        public static <V,​E> java.awt.Point translatePointFromGraphSpaceToViewSpace​(java.awt.geom.Point2D pointInGraphSpace,
                                                                                         edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer)
      • translatePointFromGraphSpaceToLayoutSpace

        public static <V,​E> java.awt.Point translatePointFromGraphSpaceToLayoutSpace​(java.awt.geom.Point2D pointInGraphSpace,
                                                                                           edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer)
      • translateShapeFromLayoutSpaceToViewSpace

        public static <V,​E> java.awt.Shape translateShapeFromLayoutSpaceToViewSpace​(java.awt.Shape shape,
                                                                                          edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer)
      • translateShapeFromLayoutSpaceToGraphSpace

        public static <V,​E> java.awt.Shape translateShapeFromLayoutSpaceToGraphSpace​(java.awt.Shape shape,
                                                                                           edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer)
      • translateShapeFromViewSpaceToLayoutSpace

        public static <V,​E> java.awt.Shape translateShapeFromViewSpaceToLayoutSpace​(java.awt.Shape shape,
                                                                                          edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer)
      • translateRectangleFromVertexRelativeSpaceToViewSpace

        public static <V,​E> java.awt.Rectangle translateRectangleFromVertexRelativeSpaceToViewSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                                          V vertex,
                                                                                                          java.awt.Rectangle rectangle)
      • translateRectangleFromLayoutSpaceToViewSpace

        public static <V,​E> java.awt.Rectangle translateRectangleFromLayoutSpaceToViewSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                                  java.awt.Rectangle rectangle)
      • getVertexFromPointInViewSpace

        public static <V,​E> V getVertexFromPointInViewSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                  java.awt.Point point)
      • getPointInViewSpaceForVertex

        public static <V,​E> java.awt.Point getPointInViewSpaceForVertex​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                              V vertex)
        Get the upper-left point of vertex in the view space (Java component space)
        Parameters:
        viewer - the viewer containing the UI
        vertex - the vertex
        Returns:
        the upper-left point of the vertex
      • translatePointFromVertexRelativeSpaceToViewSpace

        public static <V,​E> java.awt.Point translatePointFromVertexRelativeSpaceToViewSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                                  V vertex,
                                                                                                  java.awt.Point startPoint)
      • getEdgeFromPointInViewSpace

        public static <V,​E> E getEdgeFromPointInViewSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                java.awt.Point point)
      • getScaleRatioToFitInDimension

        public static java.lang.Double getScaleRatioToFitInDimension​(java.awt.Dimension currentSize,
                                                                     java.awt.Dimension targetSize)
      • setGraphScale

        public static <V,​E> void setGraphScale​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                     double scale)
      • adjustEdgePickSizeForZoom

        public static <V,​E> void adjustEdgePickSizeForZoom​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer)
      • createCollectionWithZOrderBySelection

        public static <V extends VisualVertex> java.util.List<V> createCollectionWithZOrderBySelection​(java.util.Collection<V> vertices)
        Moves the selected vertices to the end of the list of vertices so that when picked (or painted), we will prefer the selected vertices, since we have configured the algorithms for the graph stuff to prefer the last accessed vertex (like when picking and painting).
        Parameters:
        vertices - the vertices to order
        Returns:
        the given vertices, ordered by selected/emphasized state
      • createHollowEgdeLoop

        public static java.awt.Shape createHollowEgdeLoop()
      • createHollowEgdeLoopInGraphSpace

        public static java.awt.Shape createHollowEgdeLoopInGraphSpace​(java.awt.Shape vertexShape,
                                                                      double x,
                                                                      double y)
        Creates a self-loop edge to be used with a vertex that calls itself. The returned shape is hollow (not a filled loop) so that mouse hit detection does not occur in the middle of the circle.
        Parameters:
        vertexShape - The shape of the vertex for which the edge is being created.
        x - The x coordinate of the vertex
        y - The y coordinate of the vertex
        Returns:
        a self-loop edge to be used with a vertex that calls itself.
      • createEgdeLoopInGraphSpace

        public static java.awt.Shape createEgdeLoopInGraphSpace​(java.awt.Shape vertexShape,
                                                                double x,
                                                                double y)
        Creates a loop shape for a vertex that calls itself. The loop is transformed to graph space, which includes updating the size and location of the loop to be relative to the vertex.
        Parameters:
        vertexShape - The shape of the vertex for which the edge is being created.
        x - The x coordinate of the vertex
        y - The y coordinate of the vertex
        Returns:
        a loop shape for a vertex that calls itself.
      • createEgdeLoopInGraphSpace

        public static java.awt.Shape createEgdeLoopInGraphSpace​(java.awt.Shape edgeLoopShape,
                                                                java.awt.Shape vertexShape,
                                                                double x,
                                                                double y)
        Transforms the given edge loop shape to graph space, which includes updating the size and location of the loop to be relative to the vertex.
        Parameters:
        edgeLoopShape - The shape to transform
        vertexShape - The shape of the vertex for which the edge is being created
        x - The x coordinate of the vertex
        y - The y coordinate of the vertex
        Returns:
        the transformed edge loop shape
      • getEdgeShapeInGraphSpace

        public static <V,​E> java.awt.Shape getEdgeShapeInGraphSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                          E e)
      • getVertexCenterPointInViewSpace

        public static <V,​E> java.awt.geom.Point2D getVertexCenterPointInViewSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                        V v)
      • getVertexOffsetFromLayoutCenter

        public static <V,​E> java.awt.geom.Point2D.Double getVertexOffsetFromLayoutCenter​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                               V vertex)
      • getVertexOffsetFromLayoutCenterTop

        public static <V,​E> java.awt.geom.Point2D.Double getVertexOffsetFromLayoutCenterTop​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                                  V vertex)
      • getOffsetFromCenterForPointInViewSpace

        public static <V,​E> java.awt.geom.Point2D.Double getOffsetFromCenterForPointInViewSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                                      java.awt.geom.Point2D point)
      • getOffsetFromCenterInLayoutSpace

        public static <V,​E> java.awt.geom.Point2D.Double getOffsetFromCenterInLayoutSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                                java.awt.Point pointInLayoutSpace)
      • getGraphScale

        public static <V,​E> java.lang.Double getGraphScale​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> vv)
      • isScaledPastVertexInteractionThreshold

        public static <V,​E> boolean isScaledPastVertexInteractionThreshold​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer)
      • getGraphCenterInLayoutSpace

        public static <V extends VisualVertex,​E extends VisualEdge<V>> java.awt.Point getGraphCenterInLayoutSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer)
      • getTotalGraphSizeInLayoutSpace

        public static <V extends VisualVertex,​E extends VisualEdge<V>> java.awt.Rectangle getTotalGraphSizeInLayoutSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer)
      • getTotalGraphSizeInLayoutSpace

        public static <V extends VisualVertex,​E extends VisualEdge<V>> java.awt.Rectangle getTotalGraphSizeInLayoutSpace​(java.util.Collection<V> vertices,
                                                                                                                               java.util.Collection<E> edges,
                                                                                                                               com.google.common.base.Function<V,​java.awt.Rectangle> vertexToBounds,
                                                                                                                               com.google.common.base.Function<E,​java.util.List<java.awt.geom.Point2D>> edgeToArticulations)
      • getBoundsForVerticesInLayoutSpace

        public static <V,​E> java.awt.Rectangle getBoundsForVerticesInLayoutSpace​(edu.uci.ics.jung.visualization.VisualizationServer<V,​E> viewer,
                                                                                       java.util.Collection<V> vertices)
        Returns a rectangle that contains all give vertices
        Parameters:
        viewer - the viewer containing the UI
        vertices - the vertices
        Returns:
        a rectangle that contains all give vertices
      • getBoundsForVerticesInLayoutSpace

        public static <V,​E> java.awt.Rectangle getBoundsForVerticesInLayoutSpace​(java.util.Collection<V> vertices,
                                                                                       com.google.common.base.Function<V,​java.awt.Rectangle> vertexToBounds)
        Returns a rectangle that contains all vertices, in the layout space
        Parameters:
        vertices - the vertices for which to calculate the bounds
        vertexToBounds - a function that can turn a single vertex into a rectangle
        Returns:
        the bounds
      • addPaddingToRectangle

        public static void addPaddingToRectangle​(int padding,
                                                 java.awt.Rectangle rectangle)
      • layoutUsesEdgeArticulations

        public static <V extends VisualVertex,​E extends VisualEdge<V>> boolean layoutUsesEdgeArticulations​(edu.uci.ics.jung.algorithms.layout.Layout<V,​E> graphLayout)
      • getVisualGraphLayout

        public static <V extends VisualVertex,​E extends VisualEdge<V>> VisualGraphLayout<V,​E> getVisualGraphLayout​(edu.uci.ics.jung.algorithms.layout.Layout<V,​E> graphLayout)
      • getVerticesOfHoveredEdges

        public static <V extends VisualVertex,​E extends VisualEdge<V>> java.util.Collection<V> getVerticesOfHoveredEdges​(edu.uci.ics.jung.graph.Graph<V,​E> graph)
      • getVerticesOfSelectedEdges

        public static <V extends VisualVertex,​E extends VisualEdge<V>> java.util.Collection<V> getVerticesOfSelectedEdges​(edu.uci.ics.jung.graph.Graph<V,​E> graph)
        Returns a collection of vertices that are incident to selected edges.
        Parameters:
        graph - the graph from which to retrieve vertices
        Returns:
        a collection of vertices that are incident to selected edges.