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.
Treemap.js | Author: Nicolas Garcia Belmonte |
TreeUtil | An object containing some common tree manipulation methods. |
Functions | |
prune | Clears all tree nodes having depth greater than maxLevel. |
getParent | Returns the parent node of the node having id. |
getSubtree | Returns the subtree that matches the given id. |
getLeaves | Returns the leaves of the tree. |
eachLevel | Iterates on tree nodes which relative depth is less or equal than a specified level. |
each | A tree iterator. |
loadSubtrees | Appends subtrees to leaves by requesting new subtrees. |
TM | Abstract Treemap class. |
Config | Treemap configuration. |
Properties | |
tips | initial layout orientation “v” or “h” for vertical/horizontal. |
tips | Enables tips for the Treemap |
titleHeight | The height of the title. |
rootId | The id of the main container box. |
offset | Offset distance between nodes. |
levelsToShow | Depth of the plotted tree. |
Color | Configuration object to add some color to the leaves. |
allow | Set this to true if you want to add color to the nodes. |
minValue | We need to know the minimum value of the property which will be taken in account to color the leaves. |
maxValue | We need to know the maximum value of the property which will be taken in account to color the leaves. |
minColorValue | The color to be applied when displaying a min value (RGB format). |
maxColorValue | The color to be applied when displaying a max value (RGB format). |
Functions | |
initialize | TM.Squarified and TM.SliceAndDice constructor. |
Properties | |
tree | The JSON tree. |
showSubtree | The displayed JSON subtree. |
tips | This property will hold the a Mootools Tips instance if specified. |
controller | A treemap controller http://blog.thejit.org/?p=8 |
rootId | Id of the Treemap container |
Functions | |
toStyle | Transforms a JSON into a CSS style string. |
leaf | Returns a boolean value specifying if the node is a tree leaf or not. |
createBox | Constructs the proper DOM layout from a json node. |
plot | Plots a Treemap |
headBox | Creates the head div dom element that usually contains the name of a parent JSON tree node. |
bodyBox | Creates the body div dom element that usually contains a subtree dom element layout. |
contentBox | Creates the content div dom element that usually contains a leaf div dom element or head and body div dom elements. |
leafBox | Creates the leaf div dom element that usually contains nothing else. |
setColor | A JSON tree node has usually a data property containing an Array of key-value objects. |
enter | Sets the elem parameter as root and performs the layout. |
out | Takes the parent node of the currently shown subtree and performs the layout. |
view | Sets the root of the treemap to the specified Id |
resetPath | Removes the .in-path className for all tree dom elements and then adds this className to all ancestors of the given subtree. |
initializeBehavior | Binds different methods to dom elements like tips, color changing, adding or removing class names on mouseenter and mouseleave, etc. |
loadTree | Loads the subtree specified by id and plots it on the layout container. |
TM. | A JavaScript implementation of the Slice and Dice Treemap algorithm. |
Functions | |
loadFromJSON | Loads the specified JSON tree and lays it on the main container. |
compute | Called by loadFromJSON to calculate recursively all node positions and lay out the tree. |
TM.Area | Abstract Treemap class containing methods that are common to aspect ratio related algorithms. |
Functions | |
loadFromJSON | Loads the specified JSON tree and lays it on the main container. |
computeDim | Computes the dimensions and positions of a group of nodes according to a custom layout row condition. |
worstAspectRatio | Calculates the worst aspect ratio of a group of rectangles. |
avgAspectRatio | Calculates the worst aspect ratio of a group of rectangles. |
layoutLast | Performs the layout of the last computed sibling. |
TM. | A JavaScript implementation of the Squarified Treemap algorithm. |
Functions | |
compute | Called by loadFromJSON to calculate recursively all node positions and lay out the tree. |
processChildrenLayout | Computes children real areas and other useful parameters for performing the Squarified algorithm. |
squarify | Performs a heuristic method to calculate div elements sizes in order to have a good aspect ratio. |
layoutRow | Performs the layout of an array of nodes. |
TM. | A JavaScript implementation of the Strip Treemap algorithm. |
Functions | |
compute | Called by loadFromJSON to calculate recursively all node positions and lay out the tree. |
processChildrenLayout | Computes children real areas and other useful parameters for performing the Squarified algorithm. |
stripify | Performs a heuristic method to calculate div elements sizes in order to have a good compromise between aspect ratio and order. |
layoutRow | Performs the layout of an array of nodes. |
An object containing some common tree manipulation methods.
Functions | |
prune | Clears all tree nodes having depth greater than maxLevel. |
getParent | Returns the parent node of the node having id. |
getSubtree | Returns the subtree that matches the given id. |
getLeaves | Returns the leaves of the tree. |
eachLevel | Iterates on tree nodes which relative depth is less or equal than a specified level. |
each | A tree iterator. |
loadSubtrees | Appends subtrees to leaves by requesting new subtrees. |
prune: function( tree, maxLevel )
Clears all tree nodes having depth greater than maxLevel.
tree | A JSON tree object. http://blog.thejit.org |
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.
tree | A JSON tree object. http://blog.thejit.org |
id | The id of the child node whose parent will be returned. |
getSubtree: function( tree, id )
Returns the subtree that matches the given id.
tree | A JSON tree object. http://blog.thejit.org |
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 tree node (which is also a JSON tree object of course). http://blog.thejit.org |
An array having objects with two properties. The node property contains the leaf node. The level property specifies the depth of the node.
eachLevel: function( tree, initLevel, toLevel, action )
Iterates on tree nodes which relative depth is less or equal than a specified level.
tree | A JSON tree or subtree. http://blog.thejit.org |
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. |
each: function( tree, action )
A tree iterator.
tree | A JSON tree or subtree. http://blog.thejit.org |
action | A function that receives a node. |
loadSubtrees: function( tree, controller )
Appends subtrees to leaves by requesting new subtrees. with the controller.request method.
tree | A JSON tree or subtree. http://blog.thejit.org |
controller | A controller. |
Treemap configuration. Contains properties to enable customization and proper behavior of treemaps.
Properties | |
tips | initial layout orientation “v” or “h” for vertical/horizontal. |
tips | Enables tips for the Treemap |
titleHeight | The height of the title. |
rootId | The id of the main container box. |
offset | Offset distance between nodes. |
levelsToShow | Depth of the plotted tree. |
Color | Configuration object to add some color to the leaves. |
allow | Set this to true if you want to add color to the nodes. |
minValue | We need to know the minimum value of the property which will be taken in account to color the leaves. |
maxValue | We need to know the maximum value of the property which will be taken in account to color the leaves. |
minColorValue | The color to be applied when displaying a min value (RGB format). |
maxColorValue | The color to be applied when displaying a max value (RGB format). |
Functions | |
initialize | TM.Squarified and TM.SliceAndDice constructor. |
Properties | |
tree | The JSON tree. |
showSubtree | The displayed JSON subtree. |
tips | This property will hold the a Mootools Tips instance if specified. |
controller | A treemap controller http://blog.thejit.org/?p=8 |
rootId | Id of the Treemap container |
Functions | |
toStyle | Transforms a JSON into a CSS style string. |
leaf | Returns a boolean value specifying if the node is a tree leaf or not. |
createBox | Constructs the proper DOM layout from a json node. |
plot | Plots a Treemap |
headBox | Creates the head div dom element that usually contains the name of a parent JSON tree node. |
bodyBox | Creates the body div dom element that usually contains a subtree dom element layout. |
contentBox | Creates the content div dom element that usually contains a leaf div dom element or head and body div dom elements. |
leafBox | Creates the leaf div dom element that usually contains nothing else. |
setColor | A JSON tree node has usually a data property containing an Array of key-value objects. |
enter | Sets the elem parameter as root and performs the layout. |
out | Takes the parent node of the currently shown subtree and performs the layout. |
view | Sets the root of the treemap to the specified Id |
resetPath | Removes the .in-path className for all tree dom elements and then adds this className to all ancestors of the given subtree. |
initializeBehavior | Binds different methods to dom elements like tips, color changing, adding or removing class names on mouseenter and mouseleave, etc. |
loadTree | Loads the subtree specified by id and plots it on the layout container. |
initialize: function( controller )
TM.Squarified and TM.SliceAndDice constructor.
controller | A treemap controller. http://blog.thejit.org/?p=8 |
A new TM.Squarified or TM.SliceAndDice instance.
The JSON tree. http://blog.thejit.org
The displayed JSON subtree. http://blog.thejit.org
A treemap controller http://blog.thejit.org/?p=8
leaf: function( tree )
Returns a boolean value specifying if the node is a tree leaf or not.
tree | A tree node (which is also a JSON tree object of course). http://blog.thejit.org |
A boolean value specifying if the node is a tree leaf or not.
createBox: function( json, coord, html )
Constructs the proper DOM layout from a json node.
If this node is a leaf, then it creates a leaf div dom element by calling <TM.newLeaf>. Otherwise it creates a content div dom element that contains <TM.newHead> and <TM.newBody> elements.
injectTo | A DOM element where this new DOM element will be injected. |
json | A JSON subtree. http://blog.thejit.org |
coord | A coordinates object specifying width, height, left and top style properties. |
headBox: function( json, coord )
Creates the head div dom element that usually contains the name of a parent JSON tree node.
json | A JSON subtree. http://blog.thejit.org |
coord | width and height base coordinates |
A new head div dom element that has head as class name.
contentBox: function( json, coord, html )
Creates the content div dom element that usually contains a leaf div dom element or head and body div dom elements.
json | A JSON node. http://blog.thejit.org |
coord | An object containing width, height, left and top coordinates. |
html | input html wrapped by this tag. |
A new content div dom element that has content as class name.
leafBox: function( json, coord )
Creates the leaf div dom element that usually contains nothing else.
json | A JSON subtree. http://blog.thejit.org |
coord | base with and height coordinates |
A new leaf div dom element having leaf as class name.
setColor: function( json )
A JSON tree node has usually a data property containing an Array of key-value objects. This method takes the second key-value object from that array, returning a string specifying a color relative to the value property of that object.
json | A JSON subtree. http://blog.thejit.org |
A String that represents a color in hex value.
enter: function( elem )
Sets the elem parameter as root and performs the layout.
elem | A JSON subtree. http://blog.thejit.org |
resetPath: function( tree )
Removes the .in-path className for all tree dom elements and then adds this className to all ancestors of the given subtree.
tree | A tree node (which is also a JSON tree object of course). http://blog.thejit.org |
initializeBehavior: function ()
Binds different methods to dom elements like tips, color changing, adding or removing class names on mouseenter and mouseleave, etc.
_self | A TM.Squarified or TM.SliceAndDice instance. |
A JavaScript implementation of the Slice and Dice Treemap algorithm.
Go to http://blog.thejit.org to know what kind of JSON structure feeds this object.
Go to http://blog.thejit.org/?p=8 to know what kind of controller this class accepts.
Refer to the Config object to know what properties can be modified in order to customize this object.
var tm = new TM.SliceAndDice(); tm.loadFromJSON(json);
Functions | |
loadFromJSON | Loads the specified JSON tree and lays it on the main container. |
compute | Called by loadFromJSON to calculate recursively all node positions and lay out the tree. |
loadFromJSON: function ( json )
Loads the specified JSON tree and lays it on the main container.
json | A JSON subtree. http://blog.thejit.org |
compute: function( par, json, orientation )
Called by loadFromJSON to calculate recursively all node positions and lay out the tree.
par | The parent node of the json subtree. |
json | A JSON subtree. http://blog.thejit.org |
orientation | The current <Layout> orientation. This value is switched recursively. |
Abstract Treemap class containing methods that are common to aspect ratio related algorithms.
Functions | |
loadFromJSON | Loads the specified JSON tree and lays it on the main container. |
computeDim | Computes the dimensions and positions of a group of nodes according to a custom layout row condition. |
worstAspectRatio | Calculates the worst aspect ratio of a group of rectangles. |
avgAspectRatio | Calculates the worst aspect ratio of a group of rectangles. |
layoutLast | Performs the layout of the last computed sibling. |
loadFromJSON: function ( json )
Loads the specified JSON tree and lays it on the main container.
json | A JSON subtree. http://blog.thejit.org |
computeDim: function( tail, initElem, w, coord, comp )
Computes the dimensions and positions of a group of nodes according to a custom layout row condition.
tail | An array of nodes. |
initElem | An array of nodes |
w | A fixed dimension where nodes will be layed out. |
coord | A coordinates object specifying width, height, left and top style properties. |
comp | A custom comparison function |
worstAspectRatio: function( ch, w )
Calculates the worst aspect ratio of a group of rectangles. http://en.wikipedia.org/wiki/Aspect_ratio
children | An array of nodes. |
w | The fixed dimension where rectangles are being laid out. |
The worst aspect ratio.
avgAspectRatio: function( ch, w )
Calculates the worst aspect ratio of a group of rectangles. http://en.wikipedia.org/wiki/Aspect_ratio
children | An array of nodes. |
w | The fixed dimension where rectangles are being laid out. |
The worst aspect ratio.
A JavaScript implementation of the Squarified Treemap algorithm.
Go to http://blog.thejit.org to know what kind of JSON structure feeds this object.
Go to http://blog.thejit.org/?p=8 to know what kind of controller this class accepts.
Refer to the Config object to know what properties can be modified in order to customize this object.
var tm = new TM.Squarified(); tm.loadFromJSON(json);
Functions | |
compute | Called by loadFromJSON to calculate recursively all node positions and lay out the tree. |
processChildrenLayout | Computes children real areas and other useful parameters for performing the Squarified algorithm. |
squarify | Performs a heuristic method to calculate div elements sizes in order to have a good aspect ratio. |
layoutRow | Performs the layout of an array of nodes. |
compute: function( json, coord )
Called by loadFromJSON to calculate recursively all node positions and lay out the tree.
parent | The parent node of the json subtree. |
json | A JSON subtree. http://blog.thejit.org |
coord | A coordinates object specifying width, height, left and top style properties. |
processChildrenLayout: function( par, ch, coord )
Computes children real areas and other useful parameters for performing the Squarified algorithm.
parent | The parent node of the json subtree. |
ch | An Array of nodes |
coord | A coordinates object specifying width, height, left and top style properties. |
squarify: function( tail, initElem, w, coord )
Performs a heuristic method to calculate div elements sizes in order to have a good aspect ratio.
tail | An array of nodes. |
initElem | An array of nodes |
w | A fixed dimension where nodes will be layed out. |
coord | A coordinates object specifying width, height, left and top style properties. |
A JavaScript implementation of the Strip Treemap algorithm.
Go to http://blog.thejit.org to know what kind of JSON structure feeds this object.
Go to http://blog.thejit.org/?p=8 to know what kind of controller this class accepts.
Refer to the Config object to know what properties can be modified in order to customize this object.
var tm = new TM.Strip(); tm.loadFromJSON(json);
Functions | |
compute | Called by loadFromJSON to calculate recursively all node positions and lay out the tree. |
processChildrenLayout | Computes children real areas and other useful parameters for performing the Squarified algorithm. |
stripify | Performs a heuristic method to calculate div elements sizes in order to have a good compromise between aspect ratio and order. |
layoutRow | Performs the layout of an array of nodes. |
compute: function( json, coord )
Called by loadFromJSON to calculate recursively all node positions and lay out the tree.
parent | The parent node of the json subtree. |
json | A JSON subtree. http://blog.thejit.org |
coord | A coordinates object specifying width, height, left and top style properties. |
processChildrenLayout: function( par, ch, coord )
Computes children real areas and other useful parameters for performing the Squarified algorithm.
parent | The parent node of the json subtree. |
ch | An Array of nodes |
coord | A coordinates object specifying width, height, left and top style properties. |
stripify: function( tail, initElem, w, coord )
Performs a heuristic method to calculate div elements sizes in order to have a good compromise between aspect ratio and order.
tail | An array of nodes. |
initElem | An array of nodes |
w | A fixed dimension where nodes will be layed out. |
coord | A coordinates object specifying width, height, left and top style properties. |
Clears all tree nodes having depth greater than maxLevel.
prune: function( tree, maxLevel )
Returns the parent node of the node having 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 which relative depth is 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.
loadSubtrees: function( tree, controller )
TM.Squarified and TM.SliceAndDice constructor.
initialize: function( controller )
Transforms a JSON into a CSS style string.
toStyle: function( obj )
Returns a boolean value specifying if the node is a tree leaf or not.
leaf: function( tree )
Constructs the proper DOM layout from a json node.
createBox: function( json, coord, html )
Plots a Treemap
plot: function( json )
Creates the head div dom element that usually contains the name of a parent JSON tree node.
headBox: function( json, coord )
Creates the body div dom element that usually contains a subtree dom element layout.
bodyBox: function( html, coord )
Creates the content div dom element that usually contains a leaf div dom element or head and body div dom elements.
contentBox: function( json, coord, html )
Creates the leaf div dom element that usually contains nothing else.
leafBox: function( json, coord )
A JSON tree node has usually a data property containing an Array of key-value objects.
setColor: function( json )
Sets the elem parameter as root and performs the layout.
enter: function( elem )
Takes the parent node of the currently shown subtree and performs the layout.
out: function()
Sets the root of the treemap to the specified Id
view: function( id )
Removes the .in-path className for all tree dom elements and then adds this className to all ancestors of the given subtree.
resetPath: function( tree )
Binds different methods to dom elements like tips, color changing, adding or removing class names on mouseenter and mouseleave, etc.
initializeBehavior: function ()
Loads the subtree specified by id and plots it on the layout container.
loadTree: function( id )
Loads the specified JSON tree and lays it on the main container.
loadFromJSON: function ( json )
Called by loadFromJSON to calculate recursively all node positions and lay out the tree.
compute: function( par, json, orientation )
Loads the specified JSON tree and lays it on the main container.
loadFromJSON: function ( json )
Computes the dimensions and positions of a group of nodes according to a custom layout row condition.
computeDim: function( tail, initElem, w, coord, comp )
Calculates the worst aspect ratio of a group of rectangles.
worstAspectRatio: function( ch, w )
Calculates the worst aspect ratio of a group of rectangles.
avgAspectRatio: function( ch, w )
Performs the layout of the last computed sibling.
layoutLast: function( ch, w, coord )
Called by loadFromJSON to calculate recursively all node positions and lay out the tree.
compute: function( json, coord )
Computes children real areas and other useful parameters for performing the Squarified algorithm.
processChildrenLayout: function( par, ch, coord )
Performs a heuristic method to calculate div elements sizes in order to have a good aspect ratio.
squarify: function( tail, initElem, w, coord )
Performs the layout of an array of nodes.
layoutRow: function( ch, w, coord )
Called by loadFromJSON to calculate recursively all node positions and lay out the tree.
compute: function( json, coord )
Computes children real areas and other useful parameters for performing the Squarified algorithm.
processChildrenLayout: function( par, ch, coord )
Performs a heuristic method to calculate div elements sizes in order to have a good compromise between aspect ratio and order.
stripify: function( tail, initElem, w, coord )
Performs the layout of an array of nodes.
layoutRow: function( ch, w, coord )