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 void
addBends(Edge edge, Collection<Vector2d> bendPoints)
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.static void
applyUndoableClusterIdAssignment(Graph graph, HashMap<GraphElement,String> ge2newClusterID, String description, boolean enableUndo)
static void
applyUndoableEdgeReversal(Graph graph, Collection<Edge> edges, String description)
static void
applyUndoableNodeAndBendPositionUpdate(HashMap<Node,Vector2d> nodes2newPositions, HashMap<CoordinateAttribute,Vector2d> bends2newPositions, String description)
static void
applyUndoableNodePositionAndSizeUpdate(HashMap<Node,Vector2d> nodes2newPositions, HashMap<Node,Vector2d> nodes2newNodeSize, String description)
static void
applyUndoableNodePositionUpdate(HashMap<Node,Vector2d> nodes2newPositions, String description)
static void
applyUndoableNodeSizeUpdate(HashMap<Node,Vector2d> nodes2newNodeSize, String description)
static void
clearSelection()
static int
countOverlapps(Graph g, Vector2d pos, Vector2d size)
static byte[][]
createAdjacencyMatrix(Graph g, boolean directed)
Creates the adjacency matrix for a given graph.static Graph
createClusterReferenceGraph(Graph graph, HashMap<String,Integer> clusterNodeIDandNumberOfContainingNodes)
static void
displayGraph(Graph g)
displays a graph in the mainframestatic void
enumerateNodePositions(Graph graphInstance, HashMap<CoordinateAttribute,Vector2d> oldPositions)
static void
enumerateNodePositions3d(Graph graphInstance, HashMap<CoordinateAttribute,Vector3d> oldPositions)
static void
exchangePositions(List<Node> nodes, NodeSortCommand sortCommand, boolean sortConsiderCluster)
static void
exchangePositionsNHL(List<NodeHelper> nodes, NodeSortCommand sortCommand, boolean sortConsiderCluster)
static Double
getClusteringCoefficientDirected(Node n)
static Double
getClusteringCoefficientUndirected(Node n)
static Collection<String>
getClusters(Collection<? extends GraphElement> elements)
static Graph
getClusterSubGraph(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 void
getConnectedNodes(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 void
getShortestDistances(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 boolean
hasBends(Collection<Edge> edges)
Does the given collection contain edges with bends?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 graphstatic void
introduceNewBends(Graph graph, HashSet<Edge> workEdges, int minPercent, String edgeShape, int i, String description, boolean enableUndo)
static void
issueCompleteRedrawForActiveView()
static void
issueCompleteRedrawForAllViews()
this same method code is duplicated somewhere...static void
issueCompleteRedrawForGraph(Graph g)
static void
issueCompleteRedrawForView(View activeView, Graph g)
static void
moveGraph(Graph graph, double offX, double offY)
static void
moveNodes(Collection<Node> nodes, double deltaX, double deltaY)
Moves given nodes by the given delta coordinatesstatic void
postUndoableChanges(Graph myGraph, HashMap<CoordinateAttribute,Vector2d> coordinates2oldPositions, HashMap<CoordinateAttribute,Vector2d> coordinates2newPositions, String description)
static void
postUndoableChanges3d(Graph myGraph, HashMap<CoordinateAttribute,Vector3d> coordinates2oldPositions, HashMap<CoordinateAttribute,Vector3d> coordinates2newPositions, String description)
static void
postUndoableNodeAndEdgeAdditions(Graph graph, HashSet<Node> newNodes, HashSet<Edge> newEdges, String description)
static void
printNodeLayout(Graph graph)
static void
removeAllBends(Graph g, boolean enableUndo)
Deprecated.static void
removeBends(Graph graph, Collection<Edge> edges, boolean enableUndo)
static void
removeBendsBetweenSelectedNodes(Collection<Node> nodes, boolean enableUndo)
Deprecated.static Selection
removeNonValidElementsFromSelection(Selection s)
static void
selectElements(Collection<? extends Attributable> elements)
static void
selectGraphElement(Edge e)
static void
selectGraphElement(Node n)
static void
selectGraphElements(boolean clearBefore, Collection<? extends GraphElement> elements)
static void
selectGraphElements(Collection<? extends GraphElement> elements)
static void
selectNodes(boolean clearBefore, Collection<Node> nodes)
static void
selectNodes(Collection<Node> nodes)
static void
setClusterGraphNodeSizeAndPositionFromReferenceGraph(Graph mainGraph, Graph clusterBackgroundGraph, BackgroundTaskStatusProviderSupportingExternalCall statusProvider)
static void
unselectGraphElements(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
-
-