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 Summary
Constructors Constructor Description GraphHelper() -
Method Summary
Modifier and Type Method Description static voidaddBends(Edge edge, Collection<Vector2d> bendPoints)static NodeaddNodeToGraph(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.static voidapplyUndoableClusterIdAssignment(Graph graph, HashMap<GraphElement,String> ge2newClusterID, String description, boolean enableUndo)static voidapplyUndoableEdgeReversal(Graph graph, Collection<Edge> edges, String description)static voidapplyUndoableNodeAndBendPositionUpdate(HashMap<Node,Vector2d> nodes2newPositions, HashMap<CoordinateAttribute,Vector2d> bends2newPositions, String description)static voidapplyUndoableNodePositionAndSizeUpdate(HashMap<Node,Vector2d> nodes2newPositions, HashMap<Node,Vector2d> nodes2newNodeSize, String description)static voidapplyUndoableNodePositionUpdate(HashMap<Node,Vector2d> nodes2newPositions, String description)static voidapplyUndoableNodeSizeUpdate(HashMap<Node,Vector2d> nodes2newNodeSize, String description)static voidclearSelection()static intcountOverlapps(Graph g, Vector2d pos, Vector2d size)static byte[][]createAdjacencyMatrix(Graph g, boolean directed)Creates the adjacency matrix for a given graph.static GraphcreateClusterReferenceGraph(Graph graph, HashMap<String,Integer> clusterNodeIDandNumberOfContainingNodes)static voiddisplayGraph(Graph g)displays a graph in the mainframestatic voidenumerateNodePositions(Graph graphInstance, HashMap<CoordinateAttribute,Vector2d> oldPositions)static voidenumerateNodePositions3d(Graph graphInstance, HashMap<CoordinateAttribute,Vector3d> oldPositions)static voidexchangePositions(List<Node> nodes, NodeSortCommand sortCommand, boolean sortConsiderCluster)static voidexchangePositionsNHL(List<NodeHelper> nodes, NodeSortCommand sortCommand, boolean sortConsiderCluster)static DoublegetClusteringCoefficientDirected(Node n)static DoublegetClusteringCoefficientUndirected(Node n)static Collection<String>getClusters(Collection<? extends GraphElement> elements)static GraphgetClusterSubGraph(Graph mainGraph, String validClusterID)static Set<Set<Node>>getConnectedComponents(Collection<Node> nodes)static Collection<Graph>getConnectedComponentsAsCopy(List<Node> nodes)static Collection<Graph>getConnectedComponentsAsCopy(Graph graph)builds for all connected components a separate graph and returns them as a collection of graphsstatic Set<Node>getConnectedNodes(Node startNode)gets the nodes which can be reached by the the specified nodesstatic voidgetConnectedNodes(Node startNode, boolean directed, Set<Node> result)static List<NodeHelper>getHelperNodes(Graph graph)static Set<Node>getLeafNodes(Collection<Node> sourceNodes)static Set<Node>getLeafNodes(Graph graph)static List<Node>getSelectedNodes(EditorSession workSession)static Collection<Edge>getSelectedOrAllEdges()static Collection<Edge>getSelectedOrAllEdges(Selection selection, Graph graph)static Collection<Edge>getSelectedOrAllEdges(EditorSession workSession)static Collection<GraphElement>getSelectedOrAllGraphElements()static Collection<GraphElement>getSelectedOrAllGraphElements(Graph graph)static Collection<GraphElement>getSelectedOrAllGraphElements(Selection selection, Graph graph)static Collection<GraphElement>getSelectedOrAllGraphElements(EditorSession workSession)static List<NodeHelper>getSelectedOrAllHelperNodes(EditorSession workSession)static List<Node>getSelectedOrAllNodes()static List<Node>getSelectedOrAllNodes(Selection selection, Graph graph)Returns a list of the currently selected nodes.static List<Node>getSelectedOrAllNodes(EditorSession workSession)static voidgetShortestDistances(HashMap<Node,Integer> result, HashSet<Node> from, boolean directed, int currentDistance)static Collection<NodeHelper>getSortedNodeHelpers(Collection<Node> nodes, NodeSortCommand sortCommand, boolean sortConsiderCluster)static Collection<NodeHelper>getSortedNodeHelpersNHL(Collection<NodeHelper> nodes, NodeSortCommand sortCommand, boolean sortConsiderCluster)static Collection<GraphElement>getVisibleElements(Collection<GraphElement> elements)static Collection<Node>getVisibleNodes(Collection<Node> elements)static booleanhasBends(Collection<Edge> edges)Does the given collection contain edges with bends?static voidintroduceNewBends(Graph graph, HashSet<Edge> edges, int percent, String shape, int bends, boolean massCenterFromSelection, String description, boolean enableUndo)Add new bends to a graphstatic voidintroduceNewBends(Graph graph, HashSet<Edge> workEdges, int minPercent, String edgeShape, int i, String description, boolean enableUndo)static voidissueCompleteRedrawForActiveView()static voidissueCompleteRedrawForAllViews()this same method code is duplicated somewhere...static voidissueCompleteRedrawForGraph(Graph g)static voidissueCompleteRedrawForView(View activeView, Graph g)static voidmoveGraph(Graph graph, double offX, double offY)static voidmoveNodes(Collection<Node> nodes, double deltaX, double deltaY)Moves given nodes by the given delta coordinatesstatic voidpostUndoableChanges(Graph myGraph, HashMap<CoordinateAttribute,Vector2d> coordinates2oldPositions, HashMap<CoordinateAttribute,Vector2d> coordinates2newPositions, String description)static voidpostUndoableChanges3d(Graph myGraph, HashMap<CoordinateAttribute,Vector3d> coordinates2oldPositions, HashMap<CoordinateAttribute,Vector3d> coordinates2newPositions, String description)static voidpostUndoableNodeAndEdgeAdditions(Graph graph, HashSet<Node> newNodes, HashSet<Edge> newEdges, String description)static voidprintNodeLayout(Graph graph)static voidremoveAllBends(Graph g, boolean enableUndo)Deprecated.static voidremoveBends(Graph graph, Collection<Edge> edges, boolean enableUndo)static voidremoveBendsBetweenSelectedNodes(Collection<Node> nodes, boolean enableUndo)Deprecated.static SelectionremoveNonValidElementsFromSelection(Selection s)static voidselectElements(Collection<? extends Attributable> elements)static voidselectGraphElement(Edge e)static voidselectGraphElement(Node n)static voidselectGraphElements(boolean clearBefore, Collection<? extends GraphElement> elements)static voidselectGraphElements(Collection<? extends GraphElement> elements)static voidselectNodes(boolean clearBefore, Collection<Node> nodes)static voidselectNodes(Collection<Node> nodes)static voidsetClusterGraphNodeSizeAndPositionFromReferenceGraph(Graph mainGraph, Graph clusterBackgroundGraph, BackgroundTaskStatusProviderSupportingExternalCall statusProvider)static voidunselectGraphElements(Collection<? extends GraphElement> elements)
-
Constructor Details
-
GraphHelper
public GraphHelper()
-
-
Method Details
-
displayGraph
displays a graph in the mainframe- Parameters:
the- graph to be displayed
-
createClusterReferenceGraph
-
getClusterSubGraph
-
getConnectedNodes
gets the nodes which can be reached by the the specified nodes- Parameters:
startNode- node to start with- Returns:
- set of reachable nodes
-
getConnectedNodes
-
getConnectedComponentsAsCopy
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
-
getConnectedComponents
-
removeAllBends
Deprecated.Remove all bends from a graph. Please use RemoveBendsAlgorithm. -
removeBendsBetweenSelectedNodes
@Deprecated public static void removeBendsBetweenSelectedNodes(Collection<Node> nodes, boolean enableUndo)Deprecated.Please use RemoveBendsAlgorithm.- Parameters:
nodes-enableUndo-
-
hasBends
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
-
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
-
addBends
-
getSelectedOrAllNodes
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
-
getSelectedOrAllEdges
-
getSelectedOrAllEdges
-
getSelectedOrAllEdges
-
issueCompleteRedrawForView
- 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 wasnew Color(0,0,0,255).fillColor_0_100_250_100- Fill-Color. Default wasnew Color(0,100,250,100).- Returns:
- the new node.
-
getClusters
- 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
-
getSelectedOrAllNodes
-
getSelectedOrAllGraphElements
-
getSelectedOrAllGraphElements
-
getSelectedNodes
-
getSelectedOrAllHelperNodes
-
getHelperNodes
-
issueCompleteRedrawForAllViews
public static void issueCompleteRedrawForAllViews()this same method code is duplicated somewhere... in case of changes, the method name should be searched for -
issueCompleteRedrawForGraph
-
issueCompleteRedrawForActiveView
public static void issueCompleteRedrawForActiveView() -
setClusterGraphNodeSizeAndPositionFromReferenceGraph
public static void setClusterGraphNodeSizeAndPositionFromReferenceGraph(Graph mainGraph, Graph clusterBackgroundGraph, BackgroundTaskStatusProviderSupportingExternalCall statusProvider) -
printNodeLayout
-
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
-
selectGraphElements
public static void selectGraphElements(boolean clearBefore, Collection<? extends GraphElement> elements) -
unselectGraphElements
-
selectElements
-
selectGraphElement
-
selectGraphElement
-
clearSelection
public static void clearSelection() -
selectNodes
-
selectNodes
-
getSelectedOrAllGraphElements
-
applyUndoableNodePositionUpdate
-
applyUndoableNodeSizeUpdate
-
applyUndoableNodeAndBendPositionUpdate
-
applyUndoableNodePositionAndSizeUpdate
-
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
-
getLeafNodes
-
getLeafNodes
-
getVisibleElements
-
getVisibleNodes
-
moveGraph
-
moveNodes
Moves given nodes by the given delta coordinates- Parameters:
nodes-deltaX-deltaY-
-
getShortestDistances
-
applyUndoableEdgeReversal
public static void applyUndoableEdgeReversal(Graph graph, Collection<Edge> edges, String description) -
countOverlapps
-
getClusteringCoefficientUndirected
- Parameters:
n- Node- Returns:
- Null, if clustering coefficient is undefined (division by zero)
-
getClusteringCoefficientDirected
- Parameters:
n- Node- Returns:
- Null, if clustering coefficient is undefined (division by zero)
-
createAdjacencyMatrix
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-
-