Class GraphHelper

java.lang.Object
de.ipk_gatersleben.ag_nw.graffiti.GraphHelper
All Implemented Interfaces:
HelperClass

public class GraphHelper
extends Object
implements HelperClass
Graph Helper Class - A Collection of Helper routines for the work with graphs
Author:
Christian Klukas
  • Constructor Details

    • GraphHelper

      public GraphHelper()
  • Method Details

    • displayGraph

      public static void displayGraph​(Graph g)
      displays a graph in the mainframe
      Parameters:
      the - graph to be displayed
    • createClusterReferenceGraph

      public static Graph createClusterReferenceGraph​(Graph graph, HashMap<String,​Integer> clusterNodeIDandNumberOfContainingNodes)
    • getClusterSubGraph

      public static Graph getClusterSubGraph​(Graph mainGraph, String validClusterID)
    • getConnectedNodes

      public static Set<Node> getConnectedNodes​(Node startNode)
      gets the nodes which can be reached by the the specified nodes
      Parameters:
      startNode - node to start with
      Returns:
      set of reachable nodes
    • getConnectedNodes

      public static void getConnectedNodes​(Node startNode, boolean directed, Set<Node> result)
    • getConnectedComponentsAsCopy

      public static Collection<Graph> getConnectedComponentsAsCopy​(Graph graph)
      builds for all connected components a separate graph and returns them as a collection of graphs
      Parameters:
      graph - the graph to use
      Returns:
      a collection with all connected components as separate graphs
    • getConnectedComponentsAsCopy

      public static Collection<Graph> getConnectedComponentsAsCopy​(List<Node> nodes)
    • getConnectedComponents

      public static Set<Set<Node>> getConnectedComponents​(Collection<Node> nodes)
    • removeAllBends

      @Deprecated public static void removeAllBends​(Graph g, boolean enableUndo)
      Deprecated.
      Remove all bends from a graph. Please use RemoveBendsAlgorithm.
    • removeBendsBetweenSelectedNodes

      @Deprecated public static void removeBendsBetweenSelectedNodes​(Collection<Node> nodes, boolean enableUndo)
      Deprecated.
      Parameters:
      nodes -
      enableUndo -
    • hasBends

      public static boolean hasBends​(Collection<Edge> edges)
      Does the given collection contain edges with bends?
      Parameters:
      edges - a collection of edges
      Returns:
      true, if the collection of edges contains edges with bends
      Since:
      2.8.1
    • removeBends

      public static void removeBends​(Graph graph, Collection<Edge> edges, boolean enableUndo)
    • introduceNewBends

      public static void introduceNewBends​(Graph graph, HashSet<Edge> edges, int percent, String shape, int bends, boolean massCenterFromSelection, String description, boolean enableUndo)
      Add new bends to a graph
      Parameters:
      bends - Number of bends to be introduced, either 1 or 2!
    • introduceNewBends

      public static void introduceNewBends​(Graph graph, HashSet<Edge> workEdges, int minPercent, String edgeShape, int i, String description, boolean enableUndo)
    • addBends

      public static void addBends​(Edge edge, Collection<Vector2d> bendPoints)
    • getSelectedOrAllNodes

      public static List<Node> getSelectedOrAllNodes​(Selection selection, Graph graph)
      Returns a list of the currently selected nodes. If no nodes are selected, all nodes are returned.
      Returns:
      Selected or all (if no selection) Nodes, if the given graph is null, a empty list is returned.
    • getSelectedOrAllGraphElements

      public static Collection<GraphElement> getSelectedOrAllGraphElements​(Selection selection, Graph graph)
    • removeNonValidElementsFromSelection

      public static Selection removeNonValidElementsFromSelection​(Selection s)
    • getSelectedOrAllEdges

      public static Collection<Edge> getSelectedOrAllEdges()
    • getSelectedOrAllEdges

      public static Collection<Edge> getSelectedOrAllEdges​(EditorSession workSession)
    • getSelectedOrAllEdges

      public static Collection<Edge> getSelectedOrAllEdges​(Selection selection, Graph graph)
    • issueCompleteRedrawForView

      public static void issueCompleteRedrawForView​(View activeView, Graph g)
      Parameters:
      activeView -
    • addNodeToGraph

      public static Node addNodeToGraph​(Graph graph, double posx, double posy, double frameThickness_3, double width_25, double height_25, Color frameColor_0_0_0_255, Color fillColor_0_100_250_100)
      Adds a new node to a graph.
      Parameters:
      posx - Position of the new Node (X)
      posy - Position of the new Node (Y)
      frameThickness_3 - Thinkness of Frame (default was 3)
      width_25 - Width of the new node (default was 25)
      height_25 - Height of the new node (default was 25)
      frameColor_0_0_0_255 - Color of the frame, the default was new Color(0,0,0,255).
      fillColor_0_100_250_100 - Fill-Color. Default was new Color(0,100,250,100).
      Returns:
      the new node.
    • getClusters

      public static Collection<String> getClusters​(Collection<? extends GraphElement> elements)
      Parameters:
      elements - graph elements to extract Cluster IDs from
      Returns:
      A Set of distinct Strings, which contain the cluster IDs, obtained from the list of nodes.
    • getSelectedOrAllNodes

      public static List<Node> getSelectedOrAllNodes()
    • getSelectedOrAllNodes

      public static List<Node> getSelectedOrAllNodes​(EditorSession workSession)
    • getSelectedOrAllGraphElements

      public static Collection<GraphElement> getSelectedOrAllGraphElements()
    • getSelectedOrAllGraphElements

      public static Collection<GraphElement> getSelectedOrAllGraphElements​(EditorSession workSession)
    • getSelectedNodes

      public static List<Node> getSelectedNodes​(EditorSession workSession)
    • getSelectedOrAllHelperNodes

      public static List<NodeHelper> getSelectedOrAllHelperNodes​(EditorSession workSession)
    • getHelperNodes

      public static List<NodeHelper> getHelperNodes​(Graph graph)
    • issueCompleteRedrawForAllViews

      public static void issueCompleteRedrawForAllViews()
      this same method code is duplicated somewhere... in case of changes, the method name should be searched for
    • issueCompleteRedrawForGraph

      public static void issueCompleteRedrawForGraph​(Graph g)
    • issueCompleteRedrawForActiveView

      public static void issueCompleteRedrawForActiveView()
    • setClusterGraphNodeSizeAndPositionFromReferenceGraph

      public static void setClusterGraphNodeSizeAndPositionFromReferenceGraph​(Graph mainGraph, Graph clusterBackgroundGraph, BackgroundTaskStatusProviderSupportingExternalCall statusProvider)
    • printNodeLayout

      public static void printNodeLayout​(Graph graph)
    • exchangePositions

      public static void exchangePositions​(List<Node> nodes, NodeSortCommand sortCommand, boolean sortConsiderCluster)
    • exchangePositionsNHL

      public static void exchangePositionsNHL​(List<NodeHelper> nodes, NodeSortCommand sortCommand, boolean sortConsiderCluster)
    • getSortedNodeHelpers

      public static Collection<NodeHelper> getSortedNodeHelpers​(Collection<Node> nodes, NodeSortCommand sortCommand, boolean sortConsiderCluster)
    • getSortedNodeHelpersNHL

      public static Collection<NodeHelper> getSortedNodeHelpersNHL​(Collection<NodeHelper> nodes, NodeSortCommand sortCommand, boolean sortConsiderCluster)
    • selectGraphElements

      public static void selectGraphElements​(Collection<? extends GraphElement> elements)
    • selectGraphElements

      public static void selectGraphElements​(boolean clearBefore, Collection<? extends GraphElement> elements)
    • unselectGraphElements

      public static void unselectGraphElements​(Collection<? extends GraphElement> elements)
    • selectElements

      public static void selectElements​(Collection<? extends Attributable> elements)
    • selectGraphElement

      public static void selectGraphElement​(Node n)
    • selectGraphElement

      public static void selectGraphElement​(Edge e)
    • clearSelection

      public static void clearSelection()
    • selectNodes

      public static void selectNodes​(Collection<Node> nodes)
    • selectNodes

      public static void selectNodes​(boolean clearBefore, Collection<Node> nodes)
    • getSelectedOrAllGraphElements

      public static Collection<GraphElement> getSelectedOrAllGraphElements​(Graph graph)
    • applyUndoableNodePositionUpdate

      public static void applyUndoableNodePositionUpdate​(HashMap<Node,​Vector2d> nodes2newPositions, String description)
    • applyUndoableNodeSizeUpdate

      public static void applyUndoableNodeSizeUpdate​(HashMap<Node,​Vector2d> nodes2newNodeSize, String description)
    • applyUndoableNodeAndBendPositionUpdate

      public static void applyUndoableNodeAndBendPositionUpdate​(HashMap<Node,​Vector2d> nodes2newPositions, HashMap<CoordinateAttribute,​Vector2d> bends2newPositions, String description)
    • applyUndoableNodePositionAndSizeUpdate

      public static void applyUndoableNodePositionAndSizeUpdate​(HashMap<Node,​Vector2d> nodes2newPositions, HashMap<Node,​Vector2d> nodes2newNodeSize, String description)
    • postUndoableChanges

      public static void postUndoableChanges​(Graph myGraph, HashMap<CoordinateAttribute,​Vector2d> coordinates2oldPositions, HashMap<CoordinateAttribute,​Vector2d> coordinates2newPositions, String description)
    • postUndoableChanges3d

      public static void postUndoableChanges3d​(Graph myGraph, HashMap<CoordinateAttribute,​Vector3d> coordinates2oldPositions, HashMap<CoordinateAttribute,​Vector3d> coordinates2newPositions, String description)
    • enumerateNodePositions

      public static void enumerateNodePositions​(Graph graphInstance, HashMap<CoordinateAttribute,​Vector2d> oldPositions)
    • enumerateNodePositions3d

      public static void enumerateNodePositions3d​(Graph graphInstance, HashMap<CoordinateAttribute,​Vector3d> oldPositions)
    • applyUndoableClusterIdAssignment

      public static void applyUndoableClusterIdAssignment​(Graph graph, HashMap<GraphElement,​String> ge2newClusterID, String description, boolean enableUndo)
    • postUndoableNodeAndEdgeAdditions

      public static void postUndoableNodeAndEdgeAdditions​(Graph graph, HashSet<Node> newNodes, HashSet<Edge> newEdges, String description)
    • getLeafNodes

      public static Set<Node> getLeafNodes​(Graph graph)
    • getLeafNodes

      public static Set<Node> getLeafNodes​(Collection<Node> sourceNodes)
    • getVisibleElements

      public static Collection<GraphElement> getVisibleElements​(Collection<GraphElement> elements)
    • getVisibleNodes

      public static Collection<Node> getVisibleNodes​(Collection<Node> elements)
    • moveGraph

      public static void moveGraph​(Graph graph, double offX, double offY)
    • moveNodes

      public static void moveNodes​(Collection<Node> nodes, double deltaX, double deltaY)
      Moves given nodes by the given delta coordinates
      Parameters:
      nodes -
      deltaX -
      deltaY -
    • getShortestDistances

      public static void getShortestDistances​(HashMap<Node,​Integer> result, HashSet<Node> from, boolean directed, int currentDistance)
    • applyUndoableEdgeReversal

      public static void applyUndoableEdgeReversal​(Graph graph, Collection<Edge> edges, String description)
    • countOverlapps

      public static int countOverlapps​(Graph g, Vector2d pos, Vector2d size)
    • getClusteringCoefficientUndirected

      public static Double getClusteringCoefficientUndirected​(Node n)
      Parameters:
      n - Node
      Returns:
      Null, if clustering coefficient is undefined (division by zero)
    • getClusteringCoefficientDirected

      public static Double getClusteringCoefficientDirected​(Node n)
      Parameters:
      n - Node
      Returns:
      Null, if clustering coefficient is undefined (division by zero)
    • createAdjacencyMatrix

      public static byte[][] createAdjacencyMatrix​(Graph g, boolean directed)
      Creates the adjacency matrix for a given graph. It will also consider if the graph is directed. The order of the nodes in the array are the same as in the Node list of the given Graph.
      Parameters:
      g -
      directed -