Spacetree.js

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:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

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.

Summary
Spacetree.jsAuthor: Nicolas Garcia Belmonte
ConfigST global configuration object.
Properties
orientationSets the orientation layout.
labelContainerThe id for the label container.
levelsToShowDepth of the plotted tree.
offsetBaseSeparation offset between nodes.
LabelConfiguration object to customize labels size and offset.
heightLabel height (offset included)
realHeightLabel realHeight (offset excluded)
widthLabel width (offset included)
realWidthLabel realWidth (offset excluded)
offsetHeightUsed on the currently expanded subtree.
offsetWidthUsed on the currently expanded subtree.
NodeConfiguration object to customize node styles.
mode
animationTimeTime for the animation.
fpsAnimation frames per second.
ComplexA multi-purpose Complex Class with common methods.
Functions
ComplexComplex constructor.
cloneReturns a copy of the current object.
normCalculates the complex norm.
squaredNormCalculates the complex squared norm.
addReturns the result of adding two complex numbers.
prodReturns the result of multiplying two complex numbers.
conjugateReturns the conjugate for this complex.
scaleReturns the result of scaling a Complex instance.
$addReturns the result of adding two complex numbers.
$prodReturns the result of multiplying two complex numbers.
$conjugateReturns the conjugate for this complex.
$scaleReturns the result of scaling a Complex instance.
$divReturns the division of two complex numbers.
TreeProvides packages with useful methods for tree manipulation.
Functions
TreeTree constructor.
Tree.NodeEnhances the json tree node with special properties.
Functions
Tree.NodeTree.Node constructor.
Properties
selectedsets the node as selected.
drawnsets the node as visible or not.
existtreats the node as if it existed or not (somewhat similar to CSS display:none)
_parentNode parent.
posNode position
startPosnode from position
endPosnode to position
startAlphanot being used by the moment.
endAlphanot being used by the moment.
alphanot being used by the moment.
Tree.UtilProvides iterators and utility methods for trees.
Functions
setTo set multiple values to multiple properties of a tree node.
addSubtreeMakes a proper Tree object from a Tree JSON structure and inserts it where specified by id.
removeSubtreeDeletes a subtree completely.
eachIterates over tree nodes performing an action.
eachLevelIterates over tree nodes to a certain tree level performing an action.
atLevelIterates over tree nodes from a sepecified level performing an action.
getLevelReturns the current level of the tree node.
getRootReturns the tree root node.
getLeavesReturns an array of the tree leaves.
getSubtreeReturns the subtree of the node with specified id or null if it doesn’t find it.
Tree.ChildrenProvides iterators and utility methods for tree children.
Functions
eachIterates over a nodes children performing an action.
childrenReturns true if the current node has at least one node with property set to true.
getChildrenReturns a filtered array of children for the current node.
getLengthReturns the length of a filtered children array.
Tree.GroupPerforms operations on group of nodes.
Functions
requestNodesCalls the request method on the controller to request a subtree for each node.
hideCollapses group of nodes.
showExpands group of nodes.
getNodesWithChildrenFilters an array of nodes leaving only nodes with children.
Tree.PlotPerforms plotting operations.
Functions
plotPlots the spacetree
plotTreePlots nodes and edges of the tree.
plotNodePlots a tree node.
plotNodeSquaredPlots a square node.
plotEdgePlots an Edge.
hideLabelsHides all labels of the tree.
animateAnimates the graph by performing a translation from elem.startPos to elem.endPos.
Tree.LabelPermorfs all label operations like showing, hiding, setting a label to a particular position, adding/removing classNames, etc.
Functions
chkChecks 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.
initCreates a label with the same id of the specified node and sets some initial properties.
plotOnPlots the label (if this fits in canvas).
fitsInCanvasReturns true or false if the current position is between canvas limits or not.
setDivPropertiesIntended for private use: sets some label properties, such as positioning and className.
addClassAdds the specified className to the label.
setDimensionsSets label width and height based on Config.Label realWidth and realHeight values.
removeClassRemoves a specified class from the label.
hasClassReturns true if the specified class name is found in the label.
setClassSets the className property of the label with a cssClass String.
hideHides the label by adding a “hidden” className to it.
showDisplays the label by removing the “hidden” className.
Tree.GeometryPerforms geometrical computations like calculating bounding boxes, a subtree base size, etc.
Functions
dispatchMakes a value dispatch according to the current layout Works like a CSS property, either top-right-bottom-left or top|bottom - left|right.
switchOrientationChanges the tree current orientation from top to left or viceversa.
getSizeReturns label height or with, depending on the tree current orientation.
getOffsetSizeReturns label offsetHeight or offsetWidth, depending on the tree current orientation.
translateApplys a translation to the tree.
getBoundingBoxCalculates a tree bounding box.
calculateCornersIntended for private use.
getBaseSizeCalculates a subtree base size.
getTreeBaseSizeCalculates a subtree base size.
getEdgeReturns a Complex instance with the begin or end position of the edge to be plotted.
getScaledTreePositionAdjusts the tree position due to canvas scaling or translation.
treeFitsInCanvasReturns a Boolean if the current tree fits in canvas.
getFirstPosCalculates the first children position given a node position.
nextPositionCalculates a siblings node position given a node position.
setRightLevelToShowHides levels of the tree until it properly fits in canvas.
getRightLevelToShowReturns the right level to show for the current tree in order to fit in canvas.
STThe main Spacetree class.
Functions
STCreates a new ST instance.
loadFromJSONLoads a json object into the ST.
computeCalculates positions from root node.
calculatePositionsThis method implements the core algorithm to calculate node positioning.
plotThis method plots the tree.
switchPositionSwitches the tree orientation from vertical to horizontal or viceversa.
requestNodesIf the controller has a request method, it asynchonously requests subtrees for the leaves of the tree.
contractContracts selected nodes.
movePerforms the animation of the translation of the tree.
expandDetermines which nodes to expand (and expands their subtrees).
selectPathSets a “selected” flag to nodes that are in the path.
addSubtreeAdds a subtree, performing optionally an animation.
removeSubtreeRemoves a subtree, performing optionally an animation.
onClickThis method is called when clicking on a tree node.
TransAn object containing multiple type of transformations.
AnimationAn object that performs animations.

Config

ST global configuration object.  Contains important properties to enable customization and proper behavior for the ST.

Summary
Properties
orientationSets the orientation layout.
labelContainerThe id for the label container.
levelsToShowDepth of the plotted tree.
offsetBaseSeparation offset between nodes.
LabelConfiguration object to customize labels size and offset.
heightLabel height (offset included)
realHeightLabel realHeight (offset excluded)
widthLabel width (offset included)
realWidthLabel realWidth (offset excluded)
offsetHeightUsed on the currently expanded subtree.
offsetWidthUsed on the currently expanded subtree.
NodeConfiguration object to customize node styles.
mode
animationTimeTime for the animation.
fpsAnimation frames per second.

Properties

orientation

Sets the orientation layout.  Implemented orientations are left (the root node will be placed on the left side of the screen), top (the root node will be placed on top of the screen), bottom and right.

labelContainer

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.

levelsToShow

Depth of the plotted tree.  The plotted tree will be pruned in order to fit with the specified depth.  Useful when using the “request” method on the controller.

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.  Adds recursively offsetHeight between nodes for each expanded level.

offsetWidth

Used on the currently expanded subtree.  Adds recursively offsetWidth between nodes for each expanded level.

Node

Configuration object to customize node styles.  Use Config.Label to configure node width and height.

mode

If setted to “stroke” only the boundary of the node will be plotted.  If setted to fill, each node will be plotted with a backgroundfill.

animationTime

Time for the animation.

fps

Animation frames per second.

Complex

A multi-purpose Complex Class with common methods.

Summary
Functions
ComplexComplex constructor.
cloneReturns a copy of the current object.
normCalculates the complex norm.
squaredNormCalculates the complex squared norm.
addReturns the result of adding two complex numbers.
prodReturns the result of multiplying two complex numbers.
conjugateReturns the conjugate for this complex.
scaleReturns the result of scaling a Complex instance.
$addReturns the result of adding two complex numbers.
$prodReturns the result of multiplying two complex numbers.
$conjugateReturns the conjugate for this complex.
$scaleReturns the result of scaling a Complex instance.
$divReturns the division of two complex numbers.

Functions

Complex

var Complex= function()

Complex constructor.

Parameters

reA real number.
imAn real number representing the imaginary part.

Returns

A new Complex instance.

clone

clone: function()

Returns a copy of the current object.

Returns

A copy of the real object.

norm

norm: function ()

Calculates the complex norm.

Returns

A real number representing the complex norm.

squaredNorm

squaredNorm: function ()

Calculates the complex squared norm.

Returns

A real number representing the complex squared norm.

add

add: function(pos)

Returns the result of adding two complex numbers.  Does not alter the original object.

Parameters

posA Complex initialized instance.

Returns

The result of adding two complex numbers.

prod

prod: function(pos)

Returns the result of multiplying two complex numbers.  Does not alter the original object.

Parameters

posA Complex initialized instance.

Returns

The result of multiplying two complex numbers.

conjugate

conjugate: function()

Returns the conjugate for this complex.  Does not alter the original object.

Returns

The conjugate for this complex.

scale

scale: function(factor)

Returns the result of scaling a Complex instance.  Does not alter the original object.

Parameters

factorA scale factor.

Returns

The result of scaling this complex to a factor.

$add

$add: function(pos)

Returns the result of adding two complex numbers.  Alters the original object.

Parameters

posA Complex initialized instance.

Returns

The result of adding two complex numbers.

$prod

$prod:function(pos)

Returns the result of multiplying two complex numbers.  Alters the original object.

Parameters

posA Complex initialized instance.

Returns

The result of multiplying two complex numbers.

$conjugate

$conjugate: function()

Returns the conjugate for this complex.  Alters the original object.

Returns

The conjugate for this complex.

$scale

$scale: function(factor)

Returns the result of scaling a Complex instance.  Alters the original object.

Parameters

factorA scale factor.

Returns

The result of scaling this complex to a factor.

$div

$div: function(pos)

Returns the division of two complex numbers.  Alters the original object.

Parameters

posA Complex number.

Returns

The result of scaling this complex to a factor.

Tree

Provides packages with useful methods for tree manipulation.

Summary
Functions
TreeTree constructor.

Functions

Tree

var Tree = function(json)

Tree constructor.  Enhances the json tree object with some special properties.

Parameters

jsonA json tree object.

Tree.Node

Enhances the json tree node with special properties.

Summary
Functions
Tree.NodeTree.Node constructor.
Properties
selectedsets the node as selected.
drawnsets the node as visible or not.
existtreats the node as if it existed or not (somewhat similar to CSS display:none)
_parentNode parent.
posNode position
startPosnode from position
endPosnode to position
startAlphanot being used by the moment.
endAlphanot being used by the moment.
alphanot being used by the moment.

Functions

Tree.Node

Tree.Node = function (json,
_parent)

Tree.Node constructor.

Parameters

jsonA json tree object.
parentThe nodes parent node.

Properties

selected

sets the node as selected.

drawn

sets the node as visible or not.  (as in CSS visibility:hidden)

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.

Summary
Functions
setTo set multiple values to multiple properties of a tree node.
addSubtreeMakes a proper Tree object from a Tree JSON structure and inserts it where specified by id.
removeSubtreeDeletes a subtree completely.
eachIterates over tree nodes performing an action.
eachLevelIterates over tree nodes to a certain tree level performing an action.
atLevelIterates over tree nodes from a sepecified level performing an action.
getLevelReturns the current level of the tree node.
getRootReturns the tree root node.
getLeavesReturns an array of the tree leaves.
getSubtreeReturns the subtree of the node with specified id or null if it doesn’t find it.

Functions

set

set: function(tree,
props,
value)

To set multiple values to multiple properties of a tree node.

addSubtree

addSubtree: function(tree,
id,
subtree)

Makes a proper Tree object from a Tree JSON structure and inserts it where specified by id.

Parameters

treeA tree object.
idA 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
subtreeA JSON Tree object.

Returns

The transformed and appended subtree.

removeSubtree

removeSubtree: function(tree,
id,
removeRoot)

Deletes a subtree completely.

Parameters

treeA tree object.
idThe root node to be deleted.
removeRootA boolean indicating if the root node of the subtree must be also removed.

each

each: function(tree,
action)

Iterates over tree nodes performing an action.

eachLevel

eachLevel: function(tree,
levelBegin,
levelEnd,
action)

Iterates over tree nodes to a certain tree level performing an action.

atLevel

atLevel: function(tree,
level,
action)

Iterates over tree nodes from a sepecified level performing an action.

getLevel

getLevel: function(tree)

Returns the current level of the tree node.

getRoot

getRoot: function(tree)

Returns the tree root node.

getLeaves

getLeaves: function(tree)

Returns an array of the tree leaves.

getSubtree

getSubtree: function(tree,
id)

Returns the subtree of the node with specified id or null if it doesn’t find it.

Tree.Children

Provides iterators and utility methods for tree children.

Summary
Functions
eachIterates over a nodes children performing an action.
childrenReturns true if the current node has at least one node with property set to true.
getChildrenReturns a filtered array of children for the current node.
getLengthReturns the length of a filtered children array.

Functions

each

each: function(tree,
action)

Iterates over a nodes children performing an action.

children

children: function(tree,
property)

Returns true if the current node has at least one node with property set to true.

getChildren

getChildren: function(tree,
property)

Returns a filtered array of children for the current node.

getLength

getLength: function(tree,
property)

Returns the length of a filtered children array.

Tree.Group

Performs operations on group of nodes.

Summary
Functions
requestNodesCalls the request method on the controller to request a subtree for each node.
hideCollapses group of nodes.
showExpands group of nodes.
getNodesWithChildrenFilters an array of nodes leaving only nodes with children.

Functions

requestNodes

requestNodes: function(nodes,
controller)

Calls the request method on the controller to request a subtree for each node.

hide

hide: function(nodes,
canvas,
controller)

Collapses group of nodes.

show

show: function(nodes,
canvas,
controller)

Expands group of nodes.

getNodesWithChildren

getNodesWithChildren: function(nodes)

Filters an array of nodes leaving only nodes with children.

Tree.Plot

Performs plotting operations.

Summary
Functions
plotPlots the spacetree
plotTreePlots nodes and edges of the tree.
plotNodePlots a tree node.
plotNodeSquaredPlots a square node.
plotEdgePlots an Edge.
hideLabelsHides all labels of the tree.
animateAnimates the graph by performing a translation from elem.startPos to elem.endPos.

Functions

plot

plot: function(viz,
opt,
scale)

Plots the spacetree

plotTree

plotTree: function(viz,
plotLabel,
opt)

Plots nodes and edges of the tree.

plotNode

plotNode: function(node,
canvas)

Plots a tree node.

plotNodeSquared

plotNodeSquared: function(node,
canvas)

Plots a square node.  Eventually more functions could be appended to draw different types of nodes.

plotEdge

plotEdge: function(begin,
end,
canvas,
selected)

Plots an Edge.

hideLabels

hideLabels: function(subtree,
hide)

Hides all labels of the tree.

animate

animate: function(viz,
opt)

Animates the graph by performing a translation from elem.startPos to elem.endPos.

Tree.Label

Permorfs all label operations like showing, hiding, setting a label to a particular position, adding/removing classNames, etc.

Summary
Functions
chkChecks 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.
initCreates a label with the same id of the specified node and sets some initial properties.
plotOnPlots the label (if this fits in canvas).
fitsInCanvasReturns true or false if the current position is between canvas limits or not.
setDivPropertiesIntended for private use: sets some label properties, such as positioning and className.
addClassAdds the specified className to the label.
setDimensionsSets label width and height based on Config.Label realWidth and realHeight values.
removeClassRemoves a specified class from the label.
hasClassReturns true if the specified class name is found in the label.
setClassSets the className property of the label with a cssClass String.
hideHides the label by adding a “hidden” className to it.
showDisplays the label by removing the “hidden” className.

Functions

chk

chk: function(node)

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

init: function(node)

Creates a label with the same id of the specified node and sets some initial properties.

plotOn

plotOn: function (node,
canvas)

Plots the label (if this fits in canvas).

Parameters

posThe position where to put the label.  This position is relative to Canvas.
canvasA Canvas instance.

fitsInCanvas

fitsInCanvas: function(pos,
canvas)

Returns true or false if the current position is between canvas limits or not.

Parameters

posThe position where to put the label.  This position is relative to Canvas.
canvasA Canvas instance.

setDivProperties

setDivProperties: function(node,
cssClass,
canvas)

Intended for private use: sets some label properties, such as positioning and className.

Parameters

cssClassA class name.
canvasA Canvas instance.
nodeThe labels node reference.

addClass

addClass: function(node,
cssClass)

Adds the specified className to the label.

Parameters

cssClassclass name to add to label.
nodethe node label reference.

setDimensions

setDimensions: function (node)

Sets label width and height based on Config.Label realWidth and realHeight values.

removeClass

removeClass: function(node,
cssClass)

Removes a specified class from the label.

Parameters

cssClassA class name.
nodeA label’s node reference.

hasClass

hasClass: function(node,
cssClass)

Returns true if the specified class name is found in the label.  Returns false otherwise.

Parameters

cssClassA class name.
nodeA labels node reference.

Returns

A boolean value.

setClass

setClass: function(node,
cssClass)

Sets the className property of the label with a cssClass String.

Parameters

cssClassA class name.
nodeA labels node reference.

hide

hide: function(node)

Hides the label by adding a “hidden” className to it.

show

show: function(node)

Displays the label by removing the “hidden” className.

Tree.Geometry

Performs geometrical computations like calculating bounding boxes, a subtree base size, etc.

Summary
Functions
dispatchMakes a value dispatch according to the current layout Works like a CSS property, either top-right-bottom-left or top|bottom - left|right.
switchOrientationChanges the tree current orientation from top to left or viceversa.
getSizeReturns label height or with, depending on the tree current orientation.
getOffsetSizeReturns label offsetHeight or offsetWidth, depending on the tree current orientation.
translateApplys a translation to the tree.
getBoundingBoxCalculates a tree bounding box.
calculateCornersIntended for private use.
getBaseSizeCalculates a subtree base size.
getTreeBaseSizeCalculates a subtree base size.
getEdgeReturns a Complex instance with the begin or end position of the edge to be plotted.
getScaledTreePositionAdjusts the tree position due to canvas scaling or translation.
treeFitsInCanvasReturns a Boolean if the current tree fits in canvas.
getFirstPosCalculates the first children position given a node position.
nextPositionCalculates a siblings node position given a node position.
setRightLevelToShowHides levels of the tree until it properly fits in canvas.
getRightLevelToShowReturns the right level to show for the current tree in order to fit in canvas.

Functions

dispatch

dispatch: function()

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

switchOrientation: function()

Changes the tree current orientation from top to left or viceversa.

getSize

getSize: function(invert)

Returns label height or with, depending on the tree current orientation.

getOffsetSize

getOffsetSize: function()

Returns label offsetHeight or offsetWidth, depending on the tree current orientation.

translate

translate: function(tree,
pos,
prop)

Applys a translation to the tree.

getBoundingBox

getBoundingBox: function (tree)

Calculates a tree bounding box.

calculateCorners

calculateCorners: function(tree,
corners)

Intended for private use.  Performs intermediate calculations for a subtree bounding box calculation.

getBaseSize

getBaseSize: function(tree,
contracted,
type)

Calculates a subtree base size.

getTreeBaseSize

getTreeBaseSize: function(tree,
type,
level)

Calculates a subtree base size.  This is an utility function used by getBaseSize

getEdge

getEdge: function(pos,
type)

Returns a Complex instance with the begin or end position of the edge to be plotted.

getScaledTreePosition

getScaledTreePosition: function(tree,
scale)

Adjusts the tree position due to canvas scaling or translation.

treeFitsInCanvas

treeFitsInCanvas: function(tree,
canvas,
level)

Returns a Boolean if the current tree fits in canvas.

getFirstPos

getFirstPos: function(initialPos,
baseHeight)

Calculates the first children position given a node position.

nextPosition

nextPosition: function(firstPos,
offsetHeight)

Calculates a siblings node position given a node position.

setRightLevelToShow

setRightLevelToShow: function(tree,
canvas)

Hides levels of the tree until it properly fits in canvas.

getRightLevelToShow

getRightLevelToShow: function(tree,
canvas)

Returns the right level to show for the current tree in order to fit in canvas.

ST

The main Spacetree class.

Summary
Functions
STCreates a new ST instance.
loadFromJSONLoads a json object into the ST.
computeCalculates positions from root node.
calculatePositionsThis method implements the core algorithm to calculate node positioning.
plotThis method plots the tree.
switchPositionSwitches the tree orientation from vertical to horizontal or viceversa.
requestNodesIf the controller has a request method, it asynchonously requests subtrees for the leaves of the tree.
contractContracts selected nodes.
movePerforms the animation of the translation of the tree.
expandDetermines which nodes to expand (and expands their subtrees).
selectPathSets a “selected” flag to nodes that are in the path.
addSubtreeAdds a subtree, performing optionally an animation.
removeSubtreeRemoves a subtree, performing optionally an animation.
onClickThis method is called when clicking on a tree node.

Functions

ST

var ST= function(canvas,
controller)

Creates a new ST instance.

Parameters

canvasA Canvas instance.
controllera ST controller http://blog.thejit.org/?p=8

loadFromJSON

loadFromJSON: function(json)

Loads a json object into the ST.

compute

compute: function ()

Calculates positions from root node.

calculatePositions

calculatePositions: function (tree,
initialPos,
property,
contracted)

This method implements the core algorithm to calculate node positioning.

plot

plot: function()

This method plots the tree.  Note that, before plotting the tree, you have to call compute to properly calculatePositions.

switchPosition

switchPosition: function(pos,
onComplete)

Switches the tree orientation from vertical to horizontal or viceversa.

requestNodes

requestNodes: function(node,
onComplete)

If the controller has a request method, it asynchonously requests subtrees for the leaves of the tree.

contract

contract: function(onComplete,
switched)

Contracts selected nodes.

move

move: function(node,
onComplete)

Performs the animation of the translation of the tree.

expand

expand: function (node,
onComplete)

Determines which nodes to expand (and expands their subtrees).

selectPath

selectPath: function(node,
nodePrev)

Sets a “selected” flag to nodes that are in the path.

addSubtree

addSubtree: function(id,
subtree,
method,
onComplete)

Adds a subtree, performing optionally an animation.

Parameters

idA 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
subtreeA JSON Tree object.
methodoptional 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.
onCompleteAn action to perform after the animation (if any).

Returns

The transformed and appended subtree.

removeSubtree

removeSubtree: function(id,
removeRoot,
method,
onComplete)

Removes a subtree, performing optionally an animation.

Parameters

idA 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
removeRootRemove the root subtree or only its children.
methodoptional 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.
onCompleteAn action to perform after the animation (if any).

onClick

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.

Parameters

ideThe label id.  The label id is usually the same as the tree node id.
onCompleteA controller method to perform things when the animation completes.

Trans

An object containing multiple type of transformations.  Based on the mootools library http://mootools.net.

Animation

An object that performs animations.  Based on Fx.Base from Mootools.

The main Spacetree class.
var Complex= function()
Complex constructor.
clone: function()
Returns a copy of the current object.
norm: function ()
Calculates the complex norm.
squaredNorm: function ()
Calculates the complex squared norm.
add: function(pos)
Returns the result of adding two complex numbers.
prod: function(pos)
Returns the result of multiplying two complex numbers.
conjugate: function()
Returns the conjugate for this complex.
scale: function(factor)
Returns the result of scaling a Complex instance.
$add: function(pos)
Returns the result of adding two complex numbers.
$prod:function(pos)
Returns the result of multiplying two complex numbers.
$conjugate: function()
Returns the conjugate for this complex.
$scale: function(factor)
Returns the result of scaling a Complex instance.
$div: function(pos)
Returns the division of two complex numbers.
var Tree = function(json)
Tree constructor.
Tree.Node = function (json,
_parent)
Tree.Node constructor.
set: function(tree,
props,
value)
To set multiple values to multiple properties of a tree node.
addSubtree: function(tree,
id,
subtree)
Makes a proper Tree object from a Tree JSON structure and inserts it where specified by id.
Provides packages with useful methods for tree manipulation.
removeSubtree: function(tree,
id,
removeRoot)
Deletes a subtree completely.
each: function(tree,
action)
Iterates over tree nodes performing an action.
eachLevel: function(tree,
levelBegin,
levelEnd,
action)
Iterates over tree nodes to a certain tree level performing an action.
atLevel: function(tree,
level,
action)
Iterates over tree nodes from a sepecified level performing an action.
getLevel: function(tree)
Returns the current level of the tree node.
getRoot: function(tree)
Returns the tree root node.
getLeaves: function(tree)
Returns an array of the tree leaves.
getSubtree: function(tree,
id)
Returns the subtree of the node with specified id or null if it doesn’t find it.
each: function(tree,
action)
Iterates over a nodes children performing an action.
children: function(tree,
property)
Returns true if the current node has at least one node with property set to true.
getChildren: function(tree,
property)
Returns a filtered array of children for the current node.
getLength: function(tree,
property)
Returns the length of a filtered children array.
requestNodes: function(nodes,
controller)
Calls the request method on the controller to request a subtree for each node.
hide: function(nodes,
canvas,
controller)
Collapses group of nodes.
show: function(nodes,
canvas,
controller)
Expands group of nodes.
getNodesWithChildren: function(nodes)
Filters an array of nodes leaving only nodes with children.
plot: function(viz,
opt,
scale)
Plots the spacetree
plotTree: function(viz,
plotLabel,
opt)
Plots nodes and edges of the tree.
plotNode: function(node,
canvas)
Plots a tree node.
plotNodeSquared: function(node,
canvas)
Plots a square node.
plotEdge: function(begin,
end,
canvas,
selected)
Plots an Edge.
hideLabels: function(subtree,
hide)
Hides all labels of the tree.
animate: function(viz,
opt)
Animates the graph by performing a translation from elem.startPos to elem.endPos.
chk: function(node)
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: function(node)
Creates a label with the same id of the specified node and sets some initial properties.
plotOn: function (node,
canvas)
Plots the label (if this fits in canvas).
fitsInCanvas: function(pos,
canvas)
Returns true or false if the current position is between canvas limits or not.
setDivProperties: function(node,
cssClass,
canvas)
Intended for private use: sets some label properties, such as positioning and className.
addClass: function(node,
cssClass)
Adds the specified className to the label.
setDimensions: function (node)
Sets label width and height based on Config.Label realWidth and realHeight values.
Configuration object to customize labels size and offset.
removeClass: function(node,
cssClass)
Removes a specified class from the label.
hasClass: function(node,
cssClass)
Returns true if the specified class name is found in the label.
setClass: function(node,
cssClass)
Sets the className property of the label with a cssClass String.
hide: function(node)
Hides the label by adding a “hidden” className to it.
show: function(node)
Displays the label by removing the “hidden” className.
dispatch: function()
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: function()
Changes the tree current orientation from top to left or viceversa.
getSize: function(invert)
Returns label height or with, depending on the tree current orientation.
getOffsetSize: function()
Returns label offsetHeight or offsetWidth, depending on the tree current orientation.
translate: function(tree,
pos,
prop)
Applys a translation to the tree.
getBoundingBox: function (tree)
Calculates a tree bounding box.
calculateCorners: function(tree,
corners)
Intended for private use.
getBaseSize: function(tree,
contracted,
type)
Calculates a subtree base size.
getTreeBaseSize: function(tree,
type,
level)
Calculates a subtree base size.
getEdge: function(pos,
type)
Returns a Complex instance with the begin or end position of the edge to be plotted.
getScaledTreePosition: function(tree,
scale)
Adjusts the tree position due to canvas scaling or translation.
treeFitsInCanvas: function(tree,
canvas,
level)
Returns a Boolean if the current tree fits in canvas.
getFirstPos: function(initialPos,
baseHeight)
Calculates the first children position given a node position.
nextPosition: function(firstPos,
offsetHeight)
Calculates a siblings node position given a node position.
setRightLevelToShow: function(tree,
canvas)
Hides levels of the tree until it properly fits in canvas.
getRightLevelToShow: function(tree,
canvas)
Returns the right level to show for the current tree in order to fit in canvas.
var ST= function(canvas,
controller)
Creates a new ST instance.
loadFromJSON: function(json)
Loads a json object into the ST.
compute: function ()
Calculates positions from root node.
calculatePositions: function (tree,
initialPos,
property,
contracted)
This method implements the core algorithm to calculate node positioning.
plot: function()
This method plots the tree.
switchPosition: function(pos,
onComplete)
Switches the tree orientation from vertical to horizontal or viceversa.
requestNodes: function(node,
onComplete)
If the controller has a request method, it asynchonously requests subtrees for the leaves of the tree.
contract: function(onComplete,
switched)
Contracts selected nodes.
move: function(node,
onComplete)
Performs the animation of the translation of the tree.
expand: function (node,
onComplete)
Determines which nodes to expand (and expands their subtrees).
selectPath: function(node,
nodePrev)
Sets a “selected” flag to nodes that are in the path.
addSubtree: function(id,
subtree,
method,
onComplete)
Adds a subtree, performing optionally an animation.
removeSubtree: function(id,
removeRoot,
method,
onComplete)
Removes a subtree, performing optionally an animation.
onClick: function (id,
onComplete)
This method is called when clicking on a tree node.
A multi-purpose Canvas object decorator.
Close