Hyperbolic Tree |
Hyperbolic TreeSets of classes and objects to plot and calculate a hyperbolic tree. Summary
CanvasA multi-purpose Canvas object decorator. Summary
HyperLineThe HyperLine class allows you to draw “lines” on the Poincare’s disk model for Hyperbolic Geometry. You just have to specify two Complex numbers that will be used for drawing the line. Summary
sense
For private use only: sets angle direction to clockwise (true) or counterclockwise (false). Parameters
ReturnsA Boolean instance describing the sense for drawing the HyperLine. arcThroughTwoPoints
For private use only. Calculates the line equation that contains p1 and p2 over the poincare disk model of hyperbolic geometry. For more information go to: http://en.wikipedia.org- /wiki- /Poincar%C3%A9_disc_model ReturnsA set of properties describing univoquely a Hyperbolic Line. For more information on these properties please refer to the wikipedia page: http://en.wikipedia.org- /wiki- /Poincar%C3%A9_disc_model ComplexA multi-purpose Complex Class with common methods. Summary
moebiusTransformation
Calculates a moebius transformation for this point / complex. For more information go to: http://en.wikipedia.org- /wiki- /Moebius_transformation. Parameters
NodeBehaviour of the hyperbolic tree node. Summary
printInfoAsRootOn
Creates a label containing the root node information. This works by creating a div containing the node’s info property. The div has ht_rootLabel as CSS className. Finally, the node is placed near the canvas plotted node. Parameters
printInfoOn
Creates a label containing the node information. This works by creating a div containing the node’s info property. The div has ht_label as CSS className. Finally, the node is placed near the canvas plotted node. Parameters
ConfigHyperbolic Tree configuration object. This object must be passed when calling a new hyperbolic tree instance: var ht= new HT(Config, canvas); The top 9 parameters (animationTime included) are necessary to execute the HT algorithm properly. Summary
HTHyperbolic Tree (HT) class. There are three ways of generating a HT object. You can use depth, children and prob properties of the Config object to define a HT. You can also use the loadTreeArray property of the Config object to define each level of the tree. Finally, you can load a HT with a JSON array. Summary
moebiusTransformation
Calculates a moebius transformation for the hyperbolic tree. For more information go to: http://en.wikipedia.org- /wiki- /Moebius_transformation Parameters
translate
Translates the HT to the mouse position. It can also be used with any other Object / Class implementing a Mouse-like interface. Parameters
loadTree
Loads an HT with the depth, children and prob parameters stored in the Config object. loadTreeByArray
Loads an HT with the loadTreeArray parameter stored in the Config object. getNodeInfoByIdTo be set by user: execute this function when performing an event to the label. Receives the label id. This label id is also the node id, so feel free to fetch the node information by calling HT.getNodeInfoById Parameters
ObjectsIn this section you’ll find the objects that you must use in order to make a Canvas or HyperbolicTree instance. There’s three ways of doing this:
canvas
Use this object to store a new Canvas instance. ht
Use this object to store a new HT instance. |
Canvas initializer.
var Canvas= function ( canvasId, fillStyle, strokeStyle )
Canvas context handler.
getContext: function ()
Calculates canvas absolute position on HTML document.
setPosition: function()
Canvas absolute position to the HTML document.
getPosition: function()
Clears the canvas object.
clear: function ()
Draws the boundary circle for the Hyperbolic Tree.
drawMainCircle: function ()
Translates canvas coordinates system to the center of the canvas object.
translateToCenter: function()
An object that contains the canvas width and height.
getSize: function ()
Returns mouse position relative to canvas.
getPosition: function ( canvas )
Captures mouse position.
capturePosition: function( e )
HyperLine constructor.
var HyperLine= function( p1, p2 )
Draws the HyperLine on canvas.
printOn: function( canvas )
For private use only: corrects angle value based on quadrant.
correctAngle: function( relTo, dot, angle )
For private use only: sets angle direction to clockwise (true) or counterclockwise (false).
sense: function( angleBegin, angleEnd )
For private use only.
arcThroughTwoPoints: function()
Complex constructor.
var Complex= 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 )
Calculates a moebius transformation for this point / complex.
moebiusTransformation: function( theta, c )
Returns the conjugate por this complex.
conjugate: function()
Returns the result of scaling a Complex instance.
scale: function( factor )
Returns a string that shows the Complex properties.
toString: function ()
Node constructor.
function Node ( id, info )
Indicates if the node is adjacent to the node indicated by the specified id
adjacentTo: function( id )
Connects the node to the specified by id.
addAdjacency: function( id )
Creates a label containing the root node information.
printInfoAsRootOn: function ( id, canvas )
Creates a label containing the node information.
printInfoOn: function ( id, canvas )
Plots the node on canvas.
printOn: function( canvas )
Intended for private use: sets some label properties, such as positioning and className.
setDivProperties: function( cssClass, canvas, key )
Calculates node’s distance to origin.
norm: function ()
Creates a new HT instance.
var HT= function( config, canvas )
Connects nodes specified by id1 and id2.
addAdjacence: function ( id1, id2 )
Adds a node.
addNode: function( id, info )
Returns a Boolean instance indicating if node belongs to graph or not.
hasNode: function( id )
Loads parameters and places the HT.
initialize: function ()
Calculates a moebius transformation for the hyperbolic tree.
moebiusTransformation: function( theta, c )
Intended for private use: calculates node positions on canvas by performing a BFS-like algorithm
calculatePositions: function( id )
Intended for private use: calculates positions for children and grandchildren of root node.
calculateChildrenPositions: function( queue )
Prints graph / tree edges
printEdges: function()
Tranlates the HT to a given position
translateTo: function( complexTo, millisec )
For private use: sets a flag.
setFlag: function ( val )
Used for drawing the HT on a frame
printNodesAt: function( at )
Prints the HT on canvas
printOn: function( canvas )
Prints the HT nodes after being translated to a relative position.
printNodesRelativeAt: function( at )
Creates and displays labels for the centered node and its adjacent nodes.
makeLabelsForCenteredNode: function ()
Translates the HT to the mouse position.
translate: function ( Mouse )
Loads an HT with the depth, children and prob parameters stored in the Config object.
loadTree: function ()
Loads an HT with the loadTreeArray parameter stored in the Config object.
loadTreeByArray: function ()
loadTreeByJSON: function ( json_array )
Returns a node info property.
getNodeInfoById: function( ide )
Use this object to store a new Canvas instance.
var canvas
Use this object to store a new HT instance.
var ht