Packagecom.yworks.graph.model
Classpublic final class GraphUtil
InheritanceGraphUtil Inheritance Object

This class provides IGraph-related utility methods.



Public Methods
 MethodDefined By
  
addRelativePort(graph:IGraph, owner:INode, relativeX:Number, relativeY:Number):IPort
[static] Adds a new port to the graph at the node using a location that is relative to the center of the node.
GraphUtil
  
adjustPreferredSize(graph:IGraph, label:ILabel):void
[static] Adjusts the ILabel.preferredSize property of a label to fit the suggested size of its ILabelStyleRenderer.
GraphUtil
  
appendBend(graph:IGraph, edge:IEdge, x:Number, y:Number):IBend
[static] Appends a new bend to the list of bends at the given edge.
GraphUtil
  
appendBends(graph:IGraph, edge:IEdge, locations:Iterable):void
[static] Appends bends to the given edge using the provided locations.
GraphUtil
  
beginCompoundEdit(graph:IGraph, undoName:String, redoName:String):ICompoundEdit
[static] Convenience method that uses the IUndoSupport from the IGraph's ILookup to IUndoSupport.beginCompoundEdit.
GraphUtil
  
beginEdit(graph:IGraph, undoName:String, redoName:String, items:Iterable):IUndoableEdit
[static] Convenience method that uses the IUndoSupport from the IGraph's ILookup to IUndoSupport.beginEdit.
GraphUtil
  
calculatePreferredSize(graph:IGraph, item:ILabeledItem, text:String, labelModelParameter:ILabelModelParameter = null, labelStyle:ILabelStyle = null, tag:Object = null):ISize
[static] Calculates the preferred size of a label with the given properties.
GraphUtil
  
clearBends(graph:IGraph, edge:IEdge):void
[static] Removes all bends from the given edge.
GraphUtil
  
degree(graph:IGraph, portOwner:IPortOwner):int
[static] Calculates the number of edges at the given IPortOwner for this graph.
GraphUtil
  
[static] Gets the index of the bend at its IBend.owner.
GraphUtil
  
getEdgeBetween(graph:IGraph, fromOwner:IPortOwner, toOwner:IPortOwner):IEdge
[static] Finds an edge that connects from and to in the given graph.
GraphUtil
  
getEdgeForId(graph:IGraph, id:Object):IEdge
[static] Uses the DefaultGraph.MAPPER_KEY_EDGE_2_ID mapper registered with the graph's mapperRegistry to lookup the edge that corresponds to the provided id.
GraphUtil
  
[static] Gets the IFoldedGraph instance associated with this IGraph or null if none is associated with it.
GraphUtil
  
[static] Tries to retrieve an IGraph instance from the IInputModeContext.
GraphUtil
  
[static] Tries to retrieve an IGraphSelection instance from the IInputModeContext.
GraphUtil
  
[static] Gets the IGroupedGraph instance associated with this IGraph or null if none is associated with it.
GraphUtil
  
getNodeForId(graph:IGraph, id:Object):INode
[static] Uses the DefaultGraph.MAPPER_KEY_NODE_2_ID mapper registered with the graph's mapperRegistry to lookup the node that corresponds to the provided id.
GraphUtil
  
[static] Gets the source node for the given edge or null.
GraphUtil
  
[static] Gets the target node for the given edge or null.
GraphUtil
  
inDegree(graph:IGraph, portOwner:IPortOwner):int
[static] Calculates the number of incoming edges at the given IPortOwner for this graph.
GraphUtil
  
[static] Convenience method that yields the incoming edges at the given owner.
GraphUtil
  
isSelfloop(edge:IEdge):Boolean
[static] Returns whether an IEdge is a self loop.
GraphUtil
  
[static] Yields the neighbors of a given portOwner.
GraphUtil
  
[static] Yields the opposites port of an IEdge.
GraphUtil
  
[static] Yields the opposites port owner of an IEdge.
GraphUtil
  
outDegree(graph:IGraph, portOwner:IPortOwner):int
[static] Calculates the number of outgoing edges at the given IPortOwner for this graph.
GraphUtil
  
[static] Convenience method that yields the outgoing edges at the given owner.
GraphUtil
  
portDegree(graph:IGraph, port:IPort):int
[static] Calculates the number of edges at the given IPort for this graph.
GraphUtil
  
portInDegree(graph:IGraph, port:IPort):int
[static] Calculates the number of incoming edges at the given IPort for this graph.
GraphUtil
  
portOutDegree(graph:IGraph, port:IPort):int
[static] Calculates the number of outgoing edges at the given IPort for this graph.
GraphUtil
  
[static] Yields the predecessors of a given portOwner.
GraphUtil
  
removeLabeledItem(graph:IGraph, labeledItem:ILabeledItem):void
[static] Convenience method that removes a ILabeledItem from the graph.
GraphUtil
  
removePortOwner(graph:IGraph, portOwner:IPortOwner):void
[static] Convenience method that removes a IPortOwner from the graph.
GraphUtil
  
reverse(graph:IGraph, edge:IEdge):void
[static] Reverses an edge using IGraph.setPorts.
GraphUtil
  
setCenter(graph:IGraph, node:INode, center:IPoint):void
[static] Sets the center of a node to the given world coordinates.
GraphUtil
  
setRelativeLocation(graph:IGraph, port:IPort, relativeX:Number, relativeY:Number):void
[static] Tries to set the location of the port relative to its IPort.owner if the owner is a INode.
GraphUtil
  
[static] Yields the successors of a given portOwner.
GraphUtil
Method Detail
addRelativePort()method
public static function addRelativePort(graph:IGraph, owner:INode, relativeX:Number, relativeY:Number):IPort

Adds a new port to the graph at the node using a location that is relative to the center of the node.

This method will delegate to graph.addPort()

Parameters

graph:IGraph — The graph to add the port to.
 
owner:INode — The owner of the port.
 
relativeX:Number — The x offset of the port relative to the center of the node layout's center.
 
relativeY:Number — The y offset of the port relative to the center of the node layout's center.

Returns
IPort — The newly added port instance.
adjustPreferredSize()method 
public static function adjustPreferredSize(graph:IGraph, label:ILabel):void

Adjusts the ILabel.preferredSize property of a label to fit the suggested size of its ILabelStyleRenderer.

This implementation uses the ILabel.style's renderer to determine the preferred rendering size. This is useful after the label's content or style have been changed.

Parameters

graph:IGraph — The graph to use.
 
label:ILabel — The label to adjust the size for.

See also

appendBend()method 
public static function appendBend(graph:IGraph, edge:IEdge, x:Number, y:Number):IBend

Appends a new bend to the list of bends at the given edge.

This is a convenience method that delegates to IGraph.addBend.

Parameters

graph:IGraph — The graph to add the bend to.
 
edge:IEdge — The edge to add the bend to.
 
x:Number — The x coordinate of the bend's location.
 
y:Number — The y coordinate of the bend's location.

Returns
IBend — The newly created bend.
appendBends()method 
public static function appendBends(graph:IGraph, edge:IEdge, locations:Iterable):void

Appends bends to the given edge using the provided locations.

Parameters

graph:IGraph — The graph to add the bends to.
 
edge:IEdge — The edge to add the bends to.
 
locations:Iterable — A collection of com.yworks.canvas.geom.IPoints that define the bend locations.

beginCompoundEdit()method 
public static function beginCompoundEdit(graph:IGraph, undoName:String, redoName:String):ICompoundEdit

Convenience method that uses the IUndoSupport from the IGraph's ILookup to IUndoSupport.beginCompoundEdit.

Parameters

graph:IGraph — The graph to edit.
 
undoName:String — The name of the undo operation.
 
redoName:String — The name of the redo operation.

Returns
ICompoundEdit — An edit that can be used for editing. This will return a dummy implementation if no IUndoSupport is available.
beginEdit()method 
public static function beginEdit(graph:IGraph, undoName:String, redoName:String, items:Iterable):IUndoableEdit

Convenience method that uses the IUndoSupport from the IGraph's ILookup to IUndoSupport.beginEdit.

Parameters

graph:IGraph — The graph to edit.
 
undoName:String — The name of the undo operation.
 
redoName:String — The name of the redo operation.
 
items:Iterable — The items to pass to IUndoSupport.beginEdit.

Returns
IUndoableEdit — An edit that can be used for editing. This will return a dummy implementation if no IUndoSupport is available.
calculateConstrainedBounds()method 
yworks_internal static function calculateConstrainedBounds(node:INode, layout:IRectangle):IRectangle

Parameters

node:INode
 
layout:IRectangle

Returns
IRectangle
calculatePreferredSize()method 
public static function calculatePreferredSize(graph:IGraph, item:ILabeledItem, text:String, labelModelParameter:ILabelModelParameter = null, labelStyle:ILabelStyle = null, tag:Object = null):ISize

Calculates the preferred size of a label with the given properties.

Parameters

graph:IGraph — The graph to which the label will be added.
 
item:ILabeledItem — The item that will own the label.
 
text:String — The text.
 
labelModelParameter:ILabelModelParameter (default = null) — The label model parameter.
 
labelStyle:ILabelStyle (default = null) — The label style.
 
tag:Object (default = null) — The label's user tag

Returns
ISize — The size as calculated by the ILabelStyleRenderer.

Throws
ArgumentError — if the labelStyle or labelModelParameter is null and the item is neither an INode nor an IEdge.
clearBends()method 
public static function clearBends(graph:IGraph, edge:IEdge):void

Removes all bends from the given edge.

The edge must be part of this graph at the time of the invocation. This will trigger the corresponding events.

Parameters

graph:IGraph — The graph to use.
 
edge:IEdge — the edge whose bends will be removed

See also

degree()method 
public static function degree(graph:IGraph, portOwner:IPortOwner):int

Calculates the number of edges at the given IPortOwner for this graph.

Note that an edge that is both incoming and outgoing will be counted twice.

Parameters

graph:IGraph — The graph.
 
portOwner:IPortOwner — The port owner to count the degree of.

Returns
int — The number of edges that are incident to the port owner.
getBendIndex()method 
public static function getBendIndex(bend:IBend):int

Gets the index of the bend at its IBend.owner.

Parameters

bend:IBend — The bend to get the index of.

Returns
int — The zero based index of the bend in the IEdge.bends list; -1 if the bend is not part of an edge.
getEdgeBetween()method 
public static function getEdgeBetween(graph:IGraph, fromOwner:IPortOwner, toOwner:IPortOwner):IEdge

Finds an edge that connects from and to in the given graph.

Parameters

graph:IGraph — The graph to find the edge in.
 
fromOwner:IPortOwner — The source port owner of the edge to find.
 
toOwner:IPortOwner — The target port owner of the edge to find.

Returns
IEdge — An edge that satisfies the constraints or null, if none was found.
getEdgeForId()method 
public static function getEdgeForId(graph:IGraph, id:Object):IEdge

Uses the DefaultGraph.MAPPER_KEY_EDGE_2_ID mapper registered with the graph's mapperRegistry to lookup the edge that corresponds to the provided id.

If the id mapper is not registered with the graph, or if no edge is mapped to the provided id, null is returned.

Parameters

graph:IGraph — the graph that contains an edge that is mapped to the provided id
 
id:Object — the edge id

Returns
IEdge — The edge that is mapped to the provided id, or null if the id mapper is not registered with the graph or if no edge is mapped to the provided id.
getFoldedGraph()method 
public static function getFoldedGraph(graph:IGraph):IFoldedGraph

Gets the IFoldedGraph instance associated with this IGraph or null if none is associated with it.

This convenience method uses the lookup of the IGraph to obtain the IFoldedGraph.

Parameters

graph:IGraph — The graph to look up the IFoldedGraph instance.

Returns
IFoldedGraph — The implementation of the IFoldedGraph or null if graph has not been created by a FoldingManager

See also

getGraph()method 
public static function getGraph(context:IInputModeContext):IGraph

Tries to retrieve an IGraph instance from the IInputModeContext.

This will use the ILookup and if this yields nothing, it will use the ILookup of the IInputModeContext.canvasComponent or finally test if it is a GraphCanvasComponent to obtain the graph from.

Parameters

context:IInputModeContext — The context to retrieve the graph from.

Returns
IGraph — Return the graph or null.
getGraphSelection()method 
public static function getGraphSelection(context:IInputModeContext):IGraphSelection

Tries to retrieve an IGraphSelection instance from the IInputModeContext.

This will use the ILookup and if this yields nothing, it will use the ILookup of the IInputModeContext.canvasComponent or finally test if it is a GraphCanvasComponent to obtain the selection from.

Parameters

context:IInputModeContext — The context to retrieve the selection from.

Returns
IGraphSelection — Return the selection or null.
getGroupedGraph()method 
public static function getGroupedGraph(graph:IGraph):IGroupedGraph

Gets the IGroupedGraph instance associated with this IGraph or null if none is associated with it.

This convenience method uses the lookup of the IGraph to obtain the IGroupedGraph.

Parameters

graph:IGraph — The graph to look up the IGroupedGraph instance.

Returns
IGroupedGraph — The implementation of the IGroupedGraph or null if grouping is not supported by the graph.

See also

getNodeForId()method 
public static function getNodeForId(graph:IGraph, id:Object):INode

Uses the DefaultGraph.MAPPER_KEY_NODE_2_ID mapper registered with the graph's mapperRegistry to lookup the node that corresponds to the provided id.

If the id mapper is not registered with the graph, or if no node is mapped to the provided id, null is returned.

Parameters

graph:IGraph — the graph that contains a node that is mapped to the provided id
 
id:Object — the node id

Returns
INode — The node that is mapped to the provided id, or null if the id mapper is not registered with the graph or if no node is mapped to the provided id.
getSourceNode()method 
public static function getSourceNode(edge:IEdge):INode

Gets the source node for the given edge or null.

Parameters

edge:IEdge — The edge to get the IEdge.sourcePort's IPort.owner as an INode.

Returns
INode — The source node or null.
getTargetNode()method 
public static function getTargetNode(edge:IEdge):INode

Gets the target node for the given edge or null.

Parameters

edge:IEdge — The edge to get the IEdge.targetPort's IPort.owner as an INode.

Returns
INode — The target node or null.
inDegree()method 
public static function inDegree(graph:IGraph, portOwner:IPortOwner):int

Calculates the number of incoming edges at the given IPortOwner for this graph.

Parameters

graph:IGraph — The graph.
 
portOwner:IPortOwner — The port owner to count the incoming edges of.

Returns
int — The number of edges that have the port owner as their target port's owner.
inEdgesAtPortOwner()method 
public static function inEdgesAtPortOwner(graph:IGraph, owner:IPortOwner):Iterable

Convenience method that yields the incoming edges at the given owner.

Parameters

graph:IGraph — The graph to use.
 
owner:IPortOwner — The owner of the edges.

Returns
Iterable — An iterable for the incoming edges.
isSelfloop()method 
public static function isSelfloop(edge:IEdge):Boolean

Returns whether an IEdge is a self loop.

Parameters

edge:IEdge — The edge to use.

Returns
Booleantrue, if the edge is a self loop
neighbors()method 
public static function neighbors(graph:IGraph, portOwner:IPortOwner):Iterable

Yields the neighbors of a given portOwner.

Neighbors are calculated by going through all IPortOwner.ports and inspecting the IGraph.edgesAtPortOwner(IPort), collecting the opposite port owners.

Parameters

graph:IGraph — The graph to use for obtaining the adjacent edges.
 
portOwner:IPortOwner — The port owner.

Returns
Iterable — An iterable over all neighbors.
oppositePort()method 
public static function oppositePort(edge:IEdge, port:IPort):IPort

Yields the opposites port of an IEdge.

Parameters

edge:IEdge — The edge to get the opposite IPortOwner of owner from.
 
port:IPort — The port that the IEdge is connected to.

Returns
IPort — The opposite port.

Throws
ArgumentError — If port is neither the source nor target of the edge.
oppositePortOwner()method 
public static function oppositePortOwner(edge:IEdge, portOwner:IPortOwner):IPortOwner

Yields the opposites port owner of an IEdge.

Parameters

edge:IEdge — The edge to get the opposite IPortOwner of owner from.
 
portOwner:IPortOwner — The owner of the port that the IEdge is connected to.

Returns
IPortOwner — The portOwner of the opposite port.

Throws
ArgumentError — If portOwner is neither the source nor target of the edge.
outDegree()method 
public static function outDegree(graph:IGraph, portOwner:IPortOwner):int

Calculates the number of outgoing edges at the given IPortOwner for this graph.

Parameters

graph:IGraph — The graph.
 
portOwner:IPortOwner — The port owner to count the outgoing edges of.

Returns
int — The number of edges that have the port owner as their source port's owner.
outEdgesAtPortOwner()method 
public static function outEdgesAtPortOwner(graph:IGraph, owner:IPortOwner):Iterable

Convenience method that yields the outgoing edges at the given owner.

Parameters

graph:IGraph — The graph to use.
 
owner:IPortOwner — The owner of the edges.

Returns
Iterable — An iterable for the outgoing edges.
portDegree()method 
public static function portDegree(graph:IGraph, port:IPort):int

Calculates the number of edges at the given IPort for this graph.

Note that an edge that is both incoming and outgoing will be counted twice.

Parameters

graph:IGraph — The graph.
 
port:IPort — The port owner to count the degree of.

Returns
int — The number of edges that are incident to the port.
portInDegree()method 
public static function portInDegree(graph:IGraph, port:IPort):int

Calculates the number of incoming edges at the given IPort for this graph.

Parameters

graph:IGraph — The graph.
 
port:IPort — The port to count the incoming edges of.

Returns
int — The number of edges that have the port as their target port.
portOutDegree()method 
public static function portOutDegree(graph:IGraph, port:IPort):int

Calculates the number of outgoing edges at the given IPort for this graph.

Parameters

graph:IGraph — The graph.
 
port:IPort — The port to count the outgoing edges of.

Returns
int — The number of edges that have the port as their source port.
predecessors()method 
public static function predecessors(graph:IGraph, portOwner:IPortOwner):Iterable

Yields the predecessors of a given portOwner.

Neighbors are calculated by going through all IPortOwner.ports and inspecting the IGraph.edgesAtPortOwner(IPortOwner), collecting the IEdge.sourcePort owners.

Parameters

graph:IGraph — The graph to use for obtaining the adjacent edges.
 
portOwner:IPortOwner — The port owner.

Returns
Iterable — An iterable over all predecessors.
removeLabeledItem()method 
public static function removeLabeledItem(graph:IGraph, labeledItem:ILabeledItem):void

Convenience method that removes a ILabeledItem from the graph.

Parameters

graph:IGraph — The graph to remove the item from.
 
labeledItem:ILabeledItem — The item to remove.


Throws
ArgumentError — If labeledItem is neither INode nor IEdge.
removePortOwner()method 
public static function removePortOwner(graph:IGraph, portOwner:IPortOwner):void

Convenience method that removes a IPortOwner from the graph.

Parameters

graph:IGraph — The graph to remove the port owner from.
 
portOwner:IPortOwner — The port owner to remove.


Throws
ArgumentError — If portOwner is neither INode nor IEdge.
reverse()method 
public static function reverse(graph:IGraph, edge:IEdge):void

Reverses an edge using IGraph.setPorts.

Also, this method will reverse the bends by clearing them and reinserting them in reverse order if necessary if there are more than one bends.

Parameters

graph:IGraph — The edge to reverse.
 
edge:IEdge — The graph that contains the edge

setCenter()method 
public static function setCenter(graph:IGraph, node:INode, center:IPoint):void

Sets the center of a node to the given world coordinates.

This implementation delegates to IGraph.setBounds

Parameters

graph:IGraph — The graph to use
 
node:INode — The node to recenter.
 
center:IPoint — The new center coordinates of the node in the world coordinate system.

setRelativeLocation()method 
public static function setRelativeLocation(graph:IGraph, port:IPort, relativeX:Number, relativeY:Number):void

Tries to set the location of the port relative to its IPort.owner if the owner is a INode.

If the port is not owned by a node that is part of this graph, this method will throw an ArgumentError.

Parameters

graph:IGraph — the port
 
port:IPort — the new x coordinate offset relative to the center of the node's layout's center.
 
relativeX:Number — the new y coordinate offset relative to the center of the node's layout's center.
 
relativeY:Number — The graph to use.


Throws
ArgumentError — If the port is not owned by a node
successors()method 
public static function successors(graph:IGraph, portOwner:IPortOwner):Iterable

Yields the successors of a given portOwner.

Neighbors are calculated by going through all IPortOwner.ports and inspecting the IGraph.edgesAtPortOwner(IPortOwner), collecting the IEdge.targetPort owners.

Parameters

graph:IGraph — The graph to use for obtaining the adjacent edges.
 
portOwner:IPortOwner — The port owner.

Returns
Iterable — An iterable over all successors.