Author: Nicolas Garcia Belmonte
Copyright: Copyright 2008-2009 by Nicolas Garcia Belmonte.
License: BSD License
Homepage: http://thejit.org
Version: 1.0.8a
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY Nicolas Garcia Belmonte ``AS IS’’ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Nicolas Garcia Belmonte BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Spacetree.js | Author: Nicolas Garcia Belmonte |
Config | ST global configuration object. |
Properties | |
orientation | Sets the orientation layout. |
labelContainer | The id for the label container. |
levelsToShow | Depth of the plotted tree. |
offsetBase | Separation offset between nodes. |
Label | Configuration object to customize labels size and offset. |
height | Label height (offset included) |
realHeight | Label realHeight (offset excluded) |
width | Label width (offset included) |
realWidth | Label realWidth (offset excluded) |
offsetHeight | Used on the currently expanded subtree. |
offsetWidth | Used on the currently expanded subtree. |
Node | Configuration object to customize node styles. |
mode | |
animationTime | Time for the animation. |
fps | Animation frames per second. |
Complex | A multi-purpose Complex Class with common methods. |
Functions | |
Complex | Complex constructor. |
clone | Returns a copy of the current object. |
norm | Calculates the complex norm. |
squaredNorm | Calculates the complex squared norm. |
add | Returns the result of adding two complex numbers. |
prod | Returns the result of multiplying two complex numbers. |
conjugate | Returns the conjugate for this complex. |
scale | Returns the result of scaling a Complex instance. |
$add | Returns the result of adding two complex numbers. |
$prod | Returns the result of multiplying two complex numbers. |
$conjugate | Returns the conjugate for this complex. |
$scale | Returns the result of scaling a Complex instance. |
$div | Returns the division of two complex numbers. |
Tree | Provides packages with useful methods for tree manipulation. |
Functions | |
Tree | Tree constructor. |
Tree.Node | Enhances the json tree node with special properties. |
Functions | |
Tree.Node | Tree.Node constructor. |
Properties | |
selected | sets the node as selected. |
drawn | sets the node as visible or not. |
exist | treats the node as if it existed or not (somewhat similar to CSS display:none) |
_parent | Node parent. |
pos | Node position |
startPos | node from position |
endPos | node to position |
startAlpha | not being used by the moment. |
endAlpha | not being used by the moment. |
alpha | not being used by the moment. |
Tree.Util | Provides iterators and utility methods for trees. |
Functions | |
set | To set multiple values to multiple properties of a tree node. |
addSubtree | Makes a proper Tree object from a Tree JSON structure and inserts it where specified by id. |
removeSubtree | Deletes a subtree completely. |
each | Iterates over tree nodes performing an action. |
eachLevel | Iterates over tree nodes to a certain tree level performing an action. |
atLevel | Iterates over tree nodes from a sepecified level performing an action. |
getLevel | Returns the current level of the tree node. |
getRoot | Returns the tree root node. |
getLeaves | Returns an array of the tree leaves. |
getSubtree | Returns the subtree of the node with specified id or null if it doesn’t find it. |
Tree. | Provides iterators and utility methods for tree children. |
Functions | |
each | Iterates over a nodes children performing an action. |
children | Returns true if the current node has at least one node with property set to true. |
getChildren | Returns a filtered array of children for the current node. |
getLength | Returns the length of a filtered children array. |
Tree. | Performs operations on group of nodes. |
Functions | |
requestNodes | Calls the request method on the controller to request a subtree for each node. |
hide | Collapses group of nodes. |
show | Expands group of nodes. |
getNodesWithChildren | Filters an array of nodes leaving only nodes with children. |
Tree.Plot | Performs plotting operations. |
Functions | |
plot | Plots the spacetree |
plotTree | Plots nodes and edges of the tree. |
plotNode | Plots a tree node. |
plotNodeSquared | Plots a square node. |
plotEdge | Plots an Edge. |
hideLabels | Hides all labels of the tree. |
animate | Animates the graph by performing a translation from elem.startPos to elem.endPos. |
Tree. | Permorfs all label operations like showing, hiding, setting a label to a particular position, adding/removing classNames, etc. |
Functions | |
chk | Checks if a label with the homologue id of the current tree node exists and if it doesn’t it creates a label with this id. |
init | Creates a label with the same id of the specified node and sets some initial properties. |
plotOn | Plots the label (if this fits in canvas). |
fitsInCanvas | Returns true or false if the current position is between canvas limits or not. |
setDivProperties | Intended for private use: sets some label properties, such as positioning and className. |
addClass | Adds the specified className to the label. |
setDimensions | Sets label width and height based on Config.Label realWidth and realHeight values. |
removeClass | Removes a specified class from the label. |
hasClass | Returns true if the specified class name is found in the label. |
setClass | Sets the className property of the label with a cssClass String. |
hide | Hides the label by adding a “hidden” className to it. |
show | Displays the label by removing the “hidden” className. |
Tree. | Performs geometrical computations like calculating bounding boxes, a subtree base size, etc. |
Functions | |
dispatch | Makes a value dispatch according to the current layout Works like a CSS property, either top-right-bottom-left or top|bottom - left|right. |
switchOrientation | Changes the tree current orientation from top to left or viceversa. |
getSize | Returns label height or with, depending on the tree current orientation. |
getOffsetSize | Returns label offsetHeight or offsetWidth, depending on the tree current orientation. |
translate | Applys a translation to the tree. |
getBoundingBox | Calculates a tree bounding box. |
calculateCorners | Intended for private use. |
getBaseSize | Calculates a subtree base size. |
getTreeBaseSize | Calculates a subtree base size. |
getEdge | Returns a Complex instance with the begin or end position of the edge to be plotted. |
getScaledTreePosition | Adjusts the tree position due to canvas scaling or translation. |
treeFitsInCanvas | Returns a Boolean if the current tree fits in canvas. |
getFirstPos | Calculates the first children position given a node position. |
nextPosition | Calculates a siblings node position given a node position. |
setRightLevelToShow | Hides levels of the tree until it properly fits in canvas. |
getRightLevelToShow | Returns the right level to show for the current tree in order to fit in canvas. |
ST | The main Spacetree class. |
Functions | |
ST | Creates a new ST instance. |
loadFromJSON | Loads a json object into the ST. |
compute | Calculates positions from root node. |
calculatePositions | This method implements the core algorithm to calculate node positioning. |
plot | This method plots the tree. |
switchPosition | Switches the tree orientation from vertical to horizontal or viceversa. |
requestNodes | If the controller has a request method, it asynchonously requests subtrees for the leaves of the tree. |
contract | Contracts selected nodes. |
move | Performs the animation of the translation of the tree. |
expand | Determines which nodes to expand (and expands their subtrees). |
selectPath | Sets a “selected” flag to nodes that are in the path. |
addSubtree | Adds a subtree, performing optionally an animation. |
removeSubtree | Removes a subtree, performing optionally an animation. |
onClick | This method is called when clicking on a tree node. |
Trans | An object containing multiple type of transformations. |
Animation | An object that performs animations. |
ST global configuration object. Contains important properties to enable customization and proper behavior for the ST.
Properties | |
orientation | Sets the orientation layout. |
labelContainer | The id for the label container. |
levelsToShow | Depth of the plotted tree. |
offsetBase | Separation offset between nodes. |
Label | Configuration object to customize labels size and offset. |
height | Label height (offset included) |
realHeight | Label realHeight (offset excluded) |
width | Label width (offset included) |
realWidth | Label realWidth (offset excluded) |
offsetHeight | Used on the currently expanded subtree. |
offsetWidth | Used on the currently expanded subtree. |
Node | Configuration object to customize node styles. |
mode | |
animationTime | Time for the animation. |
fps | Animation frames per second. |
The id for the label container. The label container should be a div dom element where label div dom elements will be injected. You have to put the label container div dom element explicitly on your page to run the ST.
Configuration object to customize node styles. Use Config.Label to configure node width and height.
A multi-purpose Complex Class with common methods.
Functions | |
Complex | Complex constructor. |
clone | Returns a copy of the current object. |
norm | Calculates the complex norm. |
squaredNorm | Calculates the complex squared norm. |
add | Returns the result of adding two complex numbers. |
prod | Returns the result of multiplying two complex numbers. |
conjugate | Returns the conjugate for this complex. |
scale | Returns the result of scaling a Complex instance. |
$add | Returns the result of adding two complex numbers. |
$prod | Returns the result of multiplying two complex numbers. |
$conjugate | Returns the conjugate for this complex. |
$scale | Returns the result of scaling a Complex instance. |
$div | Returns the division of two complex numbers. |
Enhances the json tree node with special properties.
Functions | |
Tree.Node | Tree.Node constructor. |
Properties | |
selected | sets the node as selected. |
drawn | sets the node as visible or not. |
exist | treats the node as if it existed or not (somewhat similar to CSS display:none) |
_parent | Node parent. |
pos | Node position |
startPos | node from position |
endPos | node to position |
startAlpha | not being used by the moment. |
endAlpha | not being used by the moment. |
alpha | not being used by the moment. |
Provides iterators and utility methods for trees.
Functions | |
set | To set multiple values to multiple properties of a tree node. |
addSubtree | Makes a proper Tree object from a Tree JSON structure and inserts it where specified by id. |
removeSubtree | Deletes a subtree completely. |
each | Iterates over tree nodes performing an action. |
eachLevel | Iterates over tree nodes to a certain tree level performing an action. |
atLevel | Iterates over tree nodes from a sepecified level performing an action. |
getLevel | Returns the current level of the tree node. |
getRoot | Returns the tree root node. |
getLeaves | Returns an array of the tree leaves. |
getSubtree | Returns the subtree of the node with specified id or null if it doesn’t find it. |
addSubtree: function( tree, id, subtree )
Makes a proper Tree object from a Tree JSON structure and inserts it where specified by id.
tree | A tree object. |
id | A node identifier where this subtree will be appended. If the root of the appended subtree and the id match, then it will append the subtree children to the node specified by id |
subtree | A JSON Tree object. |
The transformed and appended subtree.
Provides iterators and utility methods for tree children.
Functions | |
each | Iterates over a nodes children performing an action. |
children | Returns true if the current node has at least one node with property set to true. |
getChildren | Returns a filtered array of children for the current node. |
getLength | Returns the length of a filtered children array. |
Performs operations on group of nodes.
Functions | |
requestNodes | Calls the request method on the controller to request a subtree for each node. |
hide | Collapses group of nodes. |
show | Expands group of nodes. |
getNodesWithChildren | Filters an array of nodes leaving only nodes with children. |
Performs plotting operations.
Functions | |
plot | Plots the spacetree |
plotTree | Plots nodes and edges of the tree. |
plotNode | Plots a tree node. |
plotNodeSquared | Plots a square node. |
plotEdge | Plots an Edge. |
hideLabels | Hides all labels of the tree. |
animate | Animates the graph by performing a translation from elem.startPos to elem.endPos. |
Permorfs all label operations like showing, hiding, setting a label to a particular position, adding/removing classNames, etc.
Functions | |
chk | Checks if a label with the homologue id of the current tree node exists and if it doesn’t it creates a label with this id. |
init | Creates a label with the same id of the specified node and sets some initial properties. |
plotOn | Plots the label (if this fits in canvas). |
fitsInCanvas | Returns true or false if the current position is between canvas limits or not. |
setDivProperties | Intended for private use: sets some label properties, such as positioning and className. |
addClass | Adds the specified className to the label. |
setDimensions | Sets label width and height based on Config.Label realWidth and realHeight values. |
removeClass | Removes a specified class from the label. |
hasClass | Returns true if the specified class name is found in the label. |
setClass | Sets the className property of the label with a cssClass String. |
hide | Hides the label by adding a “hidden” className to it. |
show | Displays the label by removing the “hidden” className. |
setDimensions: function ( node )
Sets label width and height based on Config.Label realWidth and realHeight values.
Performs geometrical computations like calculating bounding boxes, a subtree base size, etc.
Functions | |
dispatch | Makes a value dispatch according to the current layout Works like a CSS property, either top-right-bottom-left or top|bottom - left|right. |
switchOrientation | Changes the tree current orientation from top to left or viceversa. |
getSize | Returns label height or with, depending on the tree current orientation. |
getOffsetSize | Returns label offsetHeight or offsetWidth, depending on the tree current orientation. |
translate | Applys a translation to the tree. |
getBoundingBox | Calculates a tree bounding box. |
calculateCorners | Intended for private use. |
getBaseSize | Calculates a subtree base size. |
getTreeBaseSize | Calculates a subtree base size. |
getEdge | Returns a Complex instance with the begin or end position of the edge to be plotted. |
getScaledTreePosition | Adjusts the tree position due to canvas scaling or translation. |
treeFitsInCanvas | Returns a Boolean if the current tree fits in canvas. |
getFirstPos | Calculates the first children position given a node position. |
nextPosition | Calculates a siblings node position given a node position. |
setRightLevelToShow | Hides levels of the tree until it properly fits in canvas. |
getRightLevelToShow | Returns the right level to show for the current tree in order to fit in canvas. |
The main Spacetree class.
Functions | |
ST | Creates a new ST instance. |
loadFromJSON | Loads a json object into the ST. |
compute | Calculates positions from root node. |
calculatePositions | This method implements the core algorithm to calculate node positioning. |
plot | This method plots the tree. |
switchPosition | Switches the tree orientation from vertical to horizontal or viceversa. |
requestNodes | If the controller has a request method, it asynchonously requests subtrees for the leaves of the tree. |
contract | Contracts selected nodes. |
move | Performs the animation of the translation of the tree. |
expand | Determines which nodes to expand (and expands their subtrees). |
selectPath | Sets a “selected” flag to nodes that are in the path. |
addSubtree | Adds a subtree, performing optionally an animation. |
removeSubtree | Removes a subtree, performing optionally an animation. |
onClick | This method is called when clicking on a tree node. |
var ST= function( canvas, controller )
Creates a new ST instance.
canvas | A Canvas instance. |
controller | a ST controller http://blog.thejit.org/?p=8 |
plot: function()
This method plots the tree. Note that, before plotting the tree, you have to call compute to properly calculatePositions.
addSubtree: function( id, subtree, method, onComplete )
Adds a subtree, performing optionally an animation.
id | A node identifier where this subtree will be appended. If the id of the root of the appended subtree and the parameter id match, then only the subtrees children will be appended to the node specified by id |
subtree | A JSON Tree object. |
method | optional set this to animate to animate the tree after adding the subtree. You can also set this parameter to replot to just replot the subtree. |
onComplete | An action to perform after the animation (if any). |
The transformed and appended subtree.
removeSubtree: function( id, removeRoot, method, onComplete )
Removes a subtree, performing optionally an animation.
id | A node identifier where this subtree will be appended. If the id of the root of the appended subtree and the parameter id match, then only the subtrees children will be appended to the node specified by id |
removeRoot | Remove the root subtree or only its children. |
method | optional set this to animate to animate the tree after adding the subtree. You can also set this parameter to replot to just replot the subtree. |
onComplete | An action to perform after the animation (if any). |
onClick: function ( id, onComplete )
This method is called when clicking on a tree node. It mainly performs all calculations and the animation of contracting, translating and expanding pertinent nodes.
ide | The label id. The label id is usually the same as the tree node id. |
onComplete | A controller method to perform things when the animation completes. |
An object containing multiple type of transformations. Based on the mootools library http://mootools.net.
Complex constructor.
var Complex= function()
Returns a copy of the current object.
clone: function()
Calculates the complex norm.
norm: function ()
Calculates the complex squared norm.
squaredNorm: function ()
Returns the result of adding two complex numbers.
add: function( pos )
Returns the result of multiplying two complex numbers.
prod: function( pos )
Returns the conjugate for this complex.
conjugate: function()
Returns the result of scaling a Complex instance.
scale: function( factor )
Returns the result of adding two complex numbers.
$add: function( pos )
Returns the result of multiplying two complex numbers.
$prod:function( pos )
Returns the conjugate for this complex.
$conjugate: function()
Returns the result of scaling a Complex instance.
$scale: function( factor )
Returns the division of two complex numbers.
$div: function( pos )
Tree constructor.
var Tree = function( json )
Tree.Node constructor.
Tree.Node = function ( json, _parent )
To set multiple values to multiple properties of a tree node.
set: function( tree, props, value )
Makes a proper Tree object from a Tree JSON structure and inserts it where specified by id.
addSubtree: function( tree, id, subtree )
Deletes a subtree completely.
removeSubtree: function( tree, id, removeRoot )
Iterates over tree nodes performing an action.
each: function( tree, action )
Iterates over tree nodes to a certain tree level performing an action.
eachLevel: function( tree, levelBegin, levelEnd, action )
Iterates over tree nodes from a sepecified level performing an action.
atLevel: function( tree, level, action )
Returns the current level of the tree node.
getLevel: function( tree )
Returns the tree root node.
getRoot: function( tree )
Returns an array of the tree leaves.
getLeaves: function( tree )
Returns the subtree of the node with specified id or null if it doesn’t find it.
getSubtree: function( tree, id )
Iterates over a nodes children performing an action.
each: function( tree, action )
Returns true if the current node has at least one node with property set to true.
children: function( tree, property )
Returns a filtered array of children for the current node.
getChildren: function( tree, property )
Returns the length of a filtered children array.
getLength: function( tree, property )
Calls the request method on the controller to request a subtree for each node.
requestNodes: function( nodes, controller )
Collapses group of nodes.
hide: function( nodes, canvas, controller )
Expands group of nodes.
show: function( nodes, canvas, controller )
Filters an array of nodes leaving only nodes with children.
getNodesWithChildren: function( nodes )
Plots the spacetree
plot: function( viz, opt, scale )
Plots nodes and edges of the tree.
plotTree: function( viz, plotLabel, opt )
Plots a tree node.
plotNode: function( node, canvas )
Plots a square node.
plotNodeSquared: function( node, canvas )
Plots an Edge.
plotEdge: function( begin, end, canvas, selected )
Hides all labels of the tree.
hideLabels: function( subtree, hide )
Animates the graph by performing a translation from elem.startPos to elem.endPos.
animate: function( viz, opt )
Checks if a label with the homologue id of the current tree node exists and if it doesn’t it creates a label with this id.
chk: function( node )
Creates a label with the same id of the specified node and sets some initial properties.
init: function( node )
Plots the label (if this fits in canvas).
plotOn: function ( node, canvas )
Returns true or false if the current position is between canvas limits or not.
fitsInCanvas: function( pos, canvas )
Intended for private use: sets some label properties, such as positioning and className.
setDivProperties: function( node, cssClass, canvas )
Adds the specified className to the label.
addClass: function( node, cssClass )
Sets label width and height based on Config.Label realWidth and realHeight values.
setDimensions: function ( node )
Removes a specified class from the label.
removeClass: function( node, cssClass )
Returns true if the specified class name is found in the label.
hasClass: function( node, cssClass )
Sets the className property of the label with a cssClass String.
setClass: function( node, cssClass )
Hides the label by adding a “hidden” className to it.
hide: function( node )
Displays the label by removing the “hidden” className.
show: function( node )
Makes a value dispatch according to the current layout Works like a CSS property, either top-right-bottom-left or top|bottom - left|right.
dispatch: function()
Changes the tree current orientation from top to left or viceversa.
switchOrientation: function()
Returns label height or with, depending on the tree current orientation.
getSize: function( invert )
Returns label offsetHeight or offsetWidth, depending on the tree current orientation.
getOffsetSize: function()
Applys a translation to the tree.
translate: function( tree, pos, prop )
Calculates a tree bounding box.
getBoundingBox: function ( tree )
Intended for private use.
calculateCorners: function( tree, corners )
Calculates a subtree base size.
getBaseSize: function( tree, contracted, type )
Calculates a subtree base size.
getTreeBaseSize: function( tree, type, level )
Returns a Complex instance with the begin or end position of the edge to be plotted.
getEdge: function( pos, type )
Adjusts the tree position due to canvas scaling or translation.
getScaledTreePosition: function( tree, scale )
Returns a Boolean if the current tree fits in canvas.
treeFitsInCanvas: function( tree, canvas, level )
Calculates the first children position given a node position.
getFirstPos: function( initialPos, baseHeight )
Calculates a siblings node position given a node position.
nextPosition: function( firstPos, offsetHeight )
Hides levels of the tree until it properly fits in canvas.
setRightLevelToShow: function( tree, canvas )
Returns the right level to show for the current tree in order to fit in canvas.
getRightLevelToShow: function( tree, canvas )
Creates a new ST instance.
var ST= function( canvas, controller )
Loads a json object into the ST.
loadFromJSON: function( json )
Calculates positions from root node.
compute: function ()
This method implements the core algorithm to calculate node positioning.
calculatePositions: function ( tree, initialPos, property, contracted )
This method plots the tree.
plot: function()
Switches the tree orientation from vertical to horizontal or viceversa.
switchPosition: function( pos, onComplete )
If the controller has a request method, it asynchonously requests subtrees for the leaves of the tree.
requestNodes: function( node, onComplete )
Contracts selected nodes.
contract: function( onComplete, switched )
Performs the animation of the translation of the tree.
move: function( node, onComplete )
Determines which nodes to expand (and expands their subtrees).
expand: function ( node, onComplete )
Sets a “selected” flag to nodes that are in the path.
selectPath: function( node, nodePrev )
Adds a subtree, performing optionally an animation.
addSubtree: function( id, subtree, method, onComplete )
Removes a subtree, performing optionally an animation.
removeSubtree: function( id, removeRoot, method, onComplete )
This method is called when clicking on a tree node.
onClick: function ( id, onComplete )