Generic Graph, Graph.Node and Graph.Adjacence classes.
| Graph.js | Generic Graph, Graph.Node and Graph.Adjacence classes. |
| Graph | A generic Graph class. |
| Functions | |
| getNode | Returns a Graph.Node by id. |
| getAdjacence | Returns an array of Graph.Adjacence objects connecting nodes with ids id and id2. |
| addNode | Adds a node. |
| addAdjacence | Connects nodes specified by obj and obj2. |
| removeNode | Removes a Graph.Node matching the specified id. |
| removeAdjacence | Removes a Graph.Adjacence matching id1 and id2. |
| hasNode | Returns a Boolean instance indicating if the node belongs to the Graph or not. |
| Graph.Node | A Graph node. |
| Functions | |
| adjacentTo | Indicates if the node is adjacent to the node specified by id |
| getAdjacency | Returns a Graph.Adjacence object connecting the current Graph.Node and the node having id as id. |
| addAdjacency | Connects the current node and the given node. |
| removeAdjacency | Removes a Graph.Adjacence by id. |
| Graph. | A Graph adjacence (or edge). |
| Graph.Util | Graph traversal and processing utility object. |
| Functions | |
| getNode | Returns a Graph.Node by id. |
| eachNode | Iterates over Graph nodes performing an action. |
| eachAdjacency | Iterates over Graph.Node adjacencies applying the action function. |
| computeLevels | Performs a BFS traversal setting the correct depth for each node. |
| eachBFS | Performs a BFS traversal applying action to each Graph.Node. |
| eachLevel | Iterates over a node’s subgraph applying action to the nodes of relative depth between levelBegin and levelEnd. |
| eachSubgraph | Iterates over a node’s children recursively. |
| eachSubnode | Iterates over a node’s children (without deeper recursion). |
| anySubnode | Returns true if any subnode matches the given condition. |
| getSubnodes | Collects all subnodes for a specified node. |
| getParents | Returns an Array of Graph.Nodes wich are parents of the given node. |
| isDescendantOf | Returns a Boolean instance indicating if some node is descendant of the node with the given id. |
| clean | Cleans flags from nodes (by setting the flag property to false). |
A generic Graph class.
When a json graph/tree structure is loaded by Loader.loadJSON, an internal Graph representation is created.
In most cases you’ll be dealing with an already created Graph structure, so methods like Graph.addNode or Graph.addAdjacence won’t be of many use. However methods like Graph.getNode and Graph.hasNode are pretty useful.
Graph.Util provides also iterators for Graphs and advanced and useful graph operations and methods.
Loader.loadJSON, Hypertree, RGraph and ST.
An instance of this class can be accessed by using the graph parameter of a Hypertree, RGraph or ST instance
var st = new ST(canvas, config); st.graph.getNode //or any other <Graph> method. var ht = new Hypertree(canvas, config); ht.graph.getNode //or any other <Graph> method. var rg = new RGraph(canvas, config); rg.graph.getNode //or any other <Graph> method.
| Functions | |
| getNode | Returns a Graph.Node by id. |
| getAdjacence | Returns an array of Graph.Adjacence objects connecting nodes with ids id and id2. |
| addNode | Adds a node. |
| addAdjacence | Connects nodes specified by obj and obj2. |
| removeNode | Removes a Graph.Node matching the specified id. |
| removeAdjacence | Removes a Graph.Adjacence matching id1 and id2. |
| hasNode | Returns a Boolean instance indicating if the node belongs to the Graph or not. |
getNode: function( id )
Returns a Graph.Node by id.
| id | A Graph.Node id. |
A Graph.Node having id as id. Returns false otherwise.
var node = graph.getNode('someid');
getAdjacence: function ( id, id2 )
Returns an array of Graph.Adjacence objects connecting nodes with ids id and id2.
| id | A Graph.Node id. |
| id2 | A Graph.Node id. |
An Array of Graph.Adjacence objects. Returns false if there’s not a Graph.Adjacence connecting those two nodes.
addAdjacence: function ( obj, obj2, data )
Connects nodes specified by obj and obj2. If not found, nodes are created.
| obj | a Graph.Node object. |
| obj2 | Another Graph.Node object. |
| data | A DataSet object. Used to store some extra information in the Graph.Adjacence object created. |
removeAdjacence: function( id1, id2 )
Removes a Graph.Adjacence matching id1 and id2.
| id1 | A Graph.Node id. |
| id2 | A Graph.Node id. |
hasNode: function( id )
Returns a Boolean instance indicating if the node belongs to the Graph or not.
| id | Node id. |
A Boolean instance indicating if the node belongs to the graph or not.
A Graph node.
| obj | An object containing an ‘id’, ‘name’ and ‘data’ properties as described in Graph.addNode. |
| complex | Whether node position properties should contain Complex or Polar instances. |
An instance of Graph.Node is usually passed as parameter for most configuration/controller methods in the Hypertree, RGraph and ST classes.
A Graph.Node object has as properties
| id | Node id. |
| name | Node name. |
| data | Node data property containing a hash (i.e {}) with custom options. For more information see Loader.loadJSON. |
| selected | Whether the node is selected or not. Used by ST for selecting nodes that are between the root node and the selected node. |
| angleSpan | For radial layouts such as the ones performed by the Hypertree and the RGraph. Contains begin and end properties containing angle values describing the angle span for this subtree. |
| alpha | Current opacity value. |
| startAlpha | Opacity begin value. Used for interpolation. |
| endAlpha | Opacity end value. Used for interpolation. |
| pos | Current position. Can be a Complex or Polar instance. |
| startPos | Starting position. Used for interpolation. |
| endPos | Ending position. Used for interpolation. |
| Functions | |
| adjacentTo | Indicates if the node is adjacent to the node specified by id |
| getAdjacency | Returns a Graph.Adjacence object connecting the current Graph.Node and the node having id as id. |
| addAdjacency | Connects the current node and the given node. |
| removeAdjacency | Removes a Graph.Adjacence by id. |
getAdjacency: function( id )
Returns a Graph.Adjacence object connecting the current Graph.Node and the node having id as id.
| id | A node id. |
A Graph.Adjacence object or undefined.
addAdjacency: function( node, data )
Connects the current node and the given node.
| node | A Graph.Node. |
| data | Some custom hash information. |
A Graph adjacence (or edge). Connects two Graph.Nodes.
| nodeFrom | A Graph.Node. |
| nodeTo | A Graph.Node. |
| data | Some custom hash data. |
An instance of Graph.Adjacence is usually passed as parameter for some configuration/controller methods in the Hypertree, RGraph and ST classes.
A Graph.Adjacence object has as properties
| nodeFrom | A Graph.Node connected by this edge. |
| nodeTo | Another Graph.Node connected by this edge. |
| data | Node data property containing a hash (i.e {}) with custom options. For more information see Loader.loadJSON. |
| alpha | Current opacity value. |
| startAlpha | Opacity begin value. Used for interpolation. |
| endAlpha | Opacity end value. Used for interpolation. |
Graph traversal and processing utility object.
| Functions | |
| getNode | Returns a Graph.Node by id. |
| eachNode | Iterates over Graph nodes performing an action. |
| eachAdjacency | Iterates over Graph.Node adjacencies applying the action function. |
| computeLevels | Performs a BFS traversal setting the correct depth for each node. |
| eachBFS | Performs a BFS traversal applying action to each Graph.Node. |
| eachLevel | Iterates over a node’s subgraph applying action to the nodes of relative depth between levelBegin and levelEnd. |
| eachSubgraph | Iterates over a node’s children recursively. |
| eachSubnode | Iterates over a node’s children (without deeper recursion). |
| anySubnode | Returns true if any subnode matches the given condition. |
| getSubnodes | Collects all subnodes for a specified node. |
| getParents | Returns an Array of Graph.Nodes wich are parents of the given node. |
| isDescendantOf | Returns a Boolean instance indicating if some node is descendant of the node with the given id. |
| clean | Cleans flags from nodes (by setting the flag property to false). |
getNode: function( graph, id )
Returns a Graph.Node by id.
| graph | A Graph instance. |
| id | A Graph.Node id. |
A Graph node.
Graph.Util.getNode(graph, 'nodeid');
eachNode: function( graph, action, flags )
Iterates over Graph nodes performing an action.
| graph | A Graph instance. |
| action | A callback function having a Graph.Node as first formal parameter. |
Graph.Util.each(graph, function(node) {
alert(node.name);
});
eachAdjacency: function( node, action, flags )
Iterates over Graph.Node adjacencies applying the action function.
| node | A Graph.Node. |
| action | A callback function having Graph.Adjacence as first formal parameter. |
Graph.Util.eachAdjacency(node, function(adj) {
alert(adj.nodeTo.name);
});
computeLevels: function( graph, id, startDepth, flags )
Performs a BFS traversal setting the correct depth for each node.
The depth of each node can then be accessed by
node._depth
| graph | A Graph. |
| id | A starting node id for the BFS traversal. |
| startDepth | optional A minimum depth value. Default’s 0. |
eachBFS: function( graph, id, action, flags )
Performs a BFS traversal applying action to each Graph.Node.
| graph | A Graph. |
| id | A starting node id for the BFS traversal. |
| action | A callback function having a Graph.Node as first formal parameter. |
Graph.Util.eachBFS(graph, 'mynodeid', function(node) {
alert(node.name);
});
eachLevel: function( node, levelBegin, levelEnd, action, flags )
Iterates over a node’s subgraph applying action to the nodes of relative depth between levelBegin and levelEnd.
| node | A Graph.Node. |
| levelBegin | A relative level value. |
| levelEnd | A relative level value. |
| action | A callback function having a Graph.Node as first formal parameter. |
eachSubgraph: function( node, action, flags )
Iterates over a node’s children recursively.
| node | A Graph.Node. |
| action | A callback function having a Graph.Node as first formal parameter. |
Graph.Util.eachSubgraph(node, function(node) {
alert(node.name);
});
eachSubnode: function( node, action, flags )
Iterates over a node’s children (without deeper recursion).
| node | A Graph.Node. |
| action | A callback function having a Graph.Node as first formal parameter. |
Graph.Util.eachSubnode(node, function(node) {
alert(node.name);
});
anySubnode: function( node, cond, flags )
Returns true if any subnode matches the given condition.
| node | A Graph.Node. |
| cond | A callback function returning a Boolean instance. This function has as first formal parameter a Graph.Node. |
A boolean value.
Graph.Util.anySubnode(node, function(node) { return node.name == "mynodename"; });
getSubnodes: function( node, level, flags )
Collects all subnodes for a specified node. The level parameter filters nodes having relative depth of level from the root node.
| node | A Graph.Node. |
| level | optional A starting relative depth for collecting nodes. Default’s 0. |
An array of nodes.
getParents: function( node )
Returns an Array of Graph.Nodes wich are parents of the given node.
| node | A Graph.Node. |
An Array of Graph.Nodes.
var pars = Graph.Util.getParents(node);
if(pars.length > 0) {
//do stuff with parents
}
isDescendantOf: function( node, id )
Returns a Boolean instance indicating if some node is descendant of the node with the given id.
| node | A Graph.Node. |
| id | A Graph.Node id. |
Ture if node is descendant of the node with the given id. False otherwise.
var pars = Graph.Util.isDescendantOf(node, "nodeid");
clean: function( graph )
Cleans flags from nodes (by setting the flag property to false).
| graph | A Graph instance. |
Returns a Graph.Node by id.
getNode: function( id )
Returns an array of Graph.Adjacence objects connecting nodes with ids id and id2.
getAdjacence: function ( id, id2 )
Adds a node.
addNode: function( obj )
Connects nodes specified by obj and obj2.
addAdjacence: function ( obj, obj2, data )
Removes a Graph.Node matching the specified id.
removeNode: function( id )
Removes a Graph.Adjacence matching id1 and id2.
removeAdjacence: function( id1, id2 )
Returns a Boolean instance indicating if the node belongs to the Graph or not.
hasNode: function( id )
Indicates if the node is adjacent to the node specified by id
adjacentTo: function( node )
Returns a Graph.Adjacence object connecting the current Graph.Node and the node having id as id.
getAdjacency: function( id )
Connects the current node and the given node.
addAdjacency: function( node, data )
Removes a Graph.Adjacence by id.
removeAdjacency: function( id )
Returns a Graph.Node by id.
getNode: function( graph, id )
Iterates over Graph nodes performing an action.
eachNode: function( graph, action, flags )
Iterates over Graph.Node adjacencies applying the action function.
eachAdjacency: function( node, action, flags )
Performs a BFS traversal setting the correct depth for each node.
computeLevels: function( graph, id, startDepth, flags )
Performs a BFS traversal applying action to each Graph.Node.
eachBFS: function( graph, id, action, flags )
Iterates over a node’s subgraph applying action to the nodes of relative depth between levelBegin and levelEnd.
eachLevel: function( node, levelBegin, levelEnd, action, flags )
Iterates over a node’s children recursively.
eachSubgraph: function( node, action, flags )
Iterates over a node’s children (without deeper recursion).
eachSubnode: function( node, action, flags )
Returns true if any subnode matches the given condition.
anySubnode: function( node, cond, flags )
Collects all subnodes for a specified node.
getSubnodes: function( node, level, flags )
Returns an Array of Graph.Nodes wich are parents of the given node.
getParents: function( node )
Returns a Boolean instance indicating if some node is descendant of the node with the given id.
isDescendantOf: function( node, id )
Cleans flags from nodes (by setting the flag property to false).
clean: function( graph )
Loads a JSON structure to the visualization.
loadJSON: function( json, i )