Implements the RGraph class and other derived classes.
A radial layout of a tree puts the root node on the center of the canvas, places its children on the first concentric ring away from the root node, its grandchildren on a second concentric ring, and so on...
Ka-Ping Yee, Danyel Fisher, Rachna Dhamija and Marti Hearst introduced a very interesting paper called “Animated Exploration of Dynamic Graphs with Radial Layout”. In this paper they describe a way to animate a radial layout of a tree with ease-in and ease-out transitions, which make transitions from a graph’s state to another easier to understand for the viewer.
Animated Exploration of Dynamic Graphs with Radial Layout (Ka-Ping Yee, Danyel Fisher, Rachna Dhamija, Marti Hearst)
http://bailando.sims.berkeley.edu
This visualization was built from scratch, taking only the paper as inspiration, and only shares some features with this paper.
| RGraph.js | Implements the RGraph class and other derived classes. |
| RGraph | The main RGraph class |
| Functions | |
| refresh | Computes nodes’ positions and replots the tree. |
| reposition | An alias for computing new positions to endPos |
| plot | Plots the RGraph |
| compute | Computes nodes’ positions. |
| onClick | Performs all calculations and animations to center the node specified by id. |
| RGraph.Op | Performs advanced operations on trees and graphs. |
| RGraph.Plot | Performs plotting operations. |
| Functions | |
| placeLabel | Overrides abstract method placeLabel in Graph.Plot. |
| RGraph. | Here are implemented all kinds of node rendering functions. |
| RGraph. | Here are implemented all kinds of edge rendering functions. |
The main RGraph class
| canvas | A Canvas Class |
| config | A configuration/controller object. |
The configuration object can have the following properties (all properties are optional and have a default value)
General
Node
Customize the visualization nodes’ shape, color, and other style properties.
This object has as properties
If given a JSON tree or graph, a node data property contains properties which are the same as defined here but prefixed with a dollar sign (i.e $), the node properties will override the global node properties.
Edge
Customize the visualization edges’ shape, color, and other style properties.
This object has as properties
If given a JSON complex graph (defined in Loader.loadJSON), an adjacency data property contains properties which are the same as defined here but prefixed with a dollar sign (i.e $), the adjacency properties will override the global edge properties.
Animations
Controller options
You can also implement controller functions inside the configuration object. This functions are
Here goes a complete example. In most cases you won’t be forced to implement all properties and methods. In fact, all configuration properties have the default value assigned.
I won’t be instanciating a Canvas class here. If you want to know more about instanciating a Canvas class please take a look at the Canvas class documentation.
var rgraph = new RGraph(canvas, {
interpolation: 'linear',
levelDistance: 100,
withLabels: true,
Node: {
overridable: false,
type: 'circle',
color: '#ccb',
lineWidth: 1,
height: 5,
width: 5,
dim: 3
},
Edge: {
overridable: false,
type: 'line',
color: '#ccb',
lineWidth: 1
},
duration: 2500,
fps: 40,
transition: Trans.Quart.easeInOut,
clearCanvas: true,
onBeforeCompute: function(node) {
//do something onBeforeCompute
},
onAfterCompute: function () {
//do something onAfterCompute
},
onCreateLabel: function(domElement, node) {
//do something onCreateLabel
},
onPlaceLabel: function(domElement, node) {
//do something onPlaceLabel
},
onBeforePlotNode:function(node) {
//do something onBeforePlotNode
},
onAfterPlotNode: function(node) {
//do something onAfterPlotNode
},
onBeforePlotLine:function(adj) {
//do something onBeforePlotLine
},
onAfterPlotLine: function(adj) {
//do something onAfterPlotLine
}
});
compute: function( property )
Computes nodes’ positions.
| property | optional A Graph.Node position property to store the new positions. Possible values are ‘pos’, ‘endPos’ or ‘startPos’. |
onClick: function( id, opt )
Performs all calculations and animations to center the node specified by id.
| id | A Graph.Node id. |
| opt | optional An object containing some extra properties like |
rgraph.onClick('someid');
//or also...
rgraph.onClick('someid', {
hideLabels: false
});Performs plotting operations.
All Graph.Plot methods
This instance can be accessed with the fx parameter of the RGraph instance created.
var rgraph = new RGraph(canvas, config); rgraph.fx.placeLabel //or can also call any other <RGraph.Plot> method
| Functions | |
| placeLabel | Overrides abstract method placeLabel in Graph.Plot. |
placeLabel: function( tag, node, controller )
Overrides abstract method placeLabel in Graph.Plot.
| tag | A DOM label element. |
| node | A Graph.Node. |
| controller | A configuration/controller object passed to the visualization. |
Here are implemented all kinds of node rendering functions. Rendering functions implemented are ‘none’, ‘circle’, ‘triangle’, ‘rectangle’, ‘star’ and ‘square’.
You can add new Node types by implementing a new method in this class
RGraph.Plot.NodeTypes.implement({
'newnodetypename': function(node, canvas) {
//Render my node here.
}
});Here are implemented all kinds of edge rendering functions. Rendering functions implemented are ‘none’, ‘line’ and ‘arrow’.
You can add new Edge types by implementing a new method in this class
RGraph.Plot.EdgeTypes.implement({
'newedgetypename': function(adj, canvas) {
//Render my edge here.
}
});Computes nodes’ positions and replots the tree.
refresh: function()
An alias for computing new positions to endPos
reposition: function()
Plots the RGraph
plot: function()
Computes nodes’ positions.
compute: function( property )
Performs all calculations and animations to center the node specified by id.
onClick: function( id, opt )
Overrides abstract method placeLabel in Graph.Plot.
placeLabel: function( tag, node, controller )
Loads a JSON structure to the visualization.
loadJSON: function( json, i )