Provides common utility functions and the Class object used internally by the library.
Also provides the TreeUtil object for manipulating JSON tree structures
Some of the Basic utility functions and the Class system are based in the MooTools Framework http://mootools.net. Copyright © 2006-2009 Valerio Proietti, http://mad4milk.net/. MIT license http://mootools.net/license.txt.
Nicolas Garcia Belmonte
Copyright 2008-2009 by Nicolas Garcia Belmonte.
1.1.3
BSD License
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.| Core.js | Provides common utility functions and the Class object used internally by the library. |
| TreeUtil | Some common JSON tree manipulation methods. |
| Functions | |
| prune | Clears all tree nodes having depth greater than maxLevel. |
| getParent | Returns the parent node of the node having id as id. |
| getSubtree | Returns the subtree that matches the given id. |
| getLeaves | Returns the leaves of the tree. |
| eachLevel | Iterates on tree nodes with relative depth less or equal than a specified level. |
| each | A tree iterator. |
| loadSubtrees | Appends subtrees to leaves by requesting new subtrees with the request method. |
Some common JSON tree manipulation methods.
| Functions | |
| prune | Clears all tree nodes having depth greater than maxLevel. |
| getParent | Returns the parent node of the node having id as id. |
| getSubtree | Returns the subtree that matches the given id. |
| getLeaves | Returns the leaves of the tree. |
| eachLevel | Iterates on tree nodes with relative depth less or equal than a specified level. |
| each | A tree iterator. |
| loadSubtrees | Appends subtrees to leaves by requesting new subtrees with the request method. |
prune: function( tree, maxLevel )
Clears all tree nodes having depth greater than maxLevel.
| tree | A JSON tree object. For more information please see Loader.loadJSON. |
| maxLevel | An integer specifying the maximum level allowed for this tree. All nodes having depth greater than max level will be deleted. |
getParent: function( tree, id )
Returns the parent node of the node having id as id.
| tree | A JSON tree object. See also Loader.loadJSON. |
| id | The id of the child node whose parent will be returned. |
A tree JSON node if any, or false otherwise.
getSubtree: function( tree, id )
Returns the subtree that matches the given id.
| tree | A JSON tree object. See also Loader.loadJSON. |
| id | A node unique identifier. |
A subtree having a root node matching the given id. Returns null if no subtree matching the id is found.
getLeaves: function ( node, maxLevel )
Returns the leaves of the tree.
| node | A JSON tree node. See also Loader.loadJSON. |
| maxLevel | optional A subtree’s max level. |
An array having objects with two properties.
eachLevel: function( tree, initLevel, toLevel, action )
Iterates on tree nodes with relative depth less or equal than a specified level.
| tree | A JSON tree or subtree. See also Loader.loadJSON. |
| initLevel | An integer specifying the initial relative level. Usually zero. |
| toLevel | An integer specifying a top level. This method will iterate only through nodes with depth less than or equal this number. |
| action | A function that receives a node and an integer specifying the actual level of the node. |
TreeUtil.eachLevel(tree, 0, 3, function(node, depth) {
alert(node.name + ' ' + depth);
});
each: function( tree, action )
A tree iterator.
| tree | A JSON tree or subtree. See also Loader.loadJSON. |
| action | A function that receives a node. |
TreeUtil.each(tree, function(node) {
alert(node.name);
});
loadSubtrees: function( tree, controller )
Appends subtrees to leaves by requesting new subtrees with the request method.
| tree | A JSON tree node. Loader.loadJSON. |
| controller | An object that implements a request method. |
TreeUtil.loadSubtrees(leafNode, {
request: function(nodeId, level, onComplete) {
//Pseudo-code to make an ajax request for a new subtree
// that has as root id _nodeId_ and depth _level_ ...
Ajax.request({
'url': 'http://subtreerequesturl/',
onSuccess: function(json) {
onComplete.onComplete(nodeId, json);
}
});
}
});Clears all tree nodes having depth greater than maxLevel.
prune: function( tree, maxLevel )
Returns the parent node of the node having id as id.
getParent: function( tree, id )
Returns the subtree that matches the given id.
getSubtree: function( tree, id )
Returns the leaves of the tree.
getLeaves: function ( node, maxLevel )
Iterates on tree nodes with relative depth less or equal than a specified level.
eachLevel: function( tree, initLevel, toLevel, action )
A tree iterator.
each: function( tree, action )
Appends subtrees to leaves by requesting new subtrees with the request method.
loadSubtrees: function( tree, controller )
Loads a JSON structure to the visualization.
loadJSON: function( json, i )