// // This work is licensed under the Creative Commons Attribution 2.5 License. To // view a copy of this license, visit // http://creativecommons.org/licenses/by/2.5/ // or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San // Francisco, California, 94105, USA. // // All copies and derivatives of this source must contain the license statement // above and the following attribution: // // Author: Kyle Scholz http://kylescholz.com/ // Copyright: 2006 // /** * TreeNodeModel: * * Represents a node in a Tree Graph. */ var TreeNode = function( id, radius, fanAngle, startX, startY ) { // Represents the angle of entry of this node's parent edge ... // Defaults to random so edges are randomly distributed from a root node. this['rootAngle'] = parseInt(Math.random()*360); // Each node knows it's parent so we can simplify calcuation of "branch weight". this['parent']; // indicates that this nodes is selected this['selected'] = false; // indicates whether this node can move this['isStatic'] = true; // Branch weight represents the weight of all of this node's children. this['branchWeight']=0; // A unique identifier this['id'] = id; // Indicates the radius (or length of edges rooted in this node) this['radius'] = radius; // Indicates the angle that can be filled with this nodes children. this['fanAngle'] = fanAngle; // Target Angle and Radius this['target']=new Object(); this['target']['t'] = 0; this['target']['r'] = 0; // Current Position this['position']=new Object(); this['position']['x'] = startX; this['position']['y'] = startY; this['position']['t'] = 0; this['position']['r'] = 0; // This node's children this['children'] = new Array(); // TODO: Replace "children"; This is exactly the same thing. this['edges'] = new Array(); // Indicates if this node has reached it's target this['done'] = false; // JSA this['offset']=0; this['parts']=new Array(); this['part']=null; /* */ this.initParts=function() { alert("initParts"); initPart("north",0,120); initPart("south",180,120); } this.initPart=function(id,ra,fa) { part=new Object(); part['rootAngle']=ra; part['fanAngle']=fa; part['children']=0; this.parts[id]=part; } } /* * Increments this branch's weight. */ this.incrementBranchWeight = function() { this['branchWeight']++; if ( this['parent'] ) { this['parent'].incrementBranchWeight(); } }; /* * Adds a child to this node. jsa-add offsetAngle */ this.addEdge = function( node, partId ) { this['children'].push(node); node['parent'] = this; node['isStatic'] = false; node['edges'].push(this); if (partId!=null) { part=this.parts[partId]; part['children']=part['children']+1; node['part']=part; node['position']['t'] = part['rootAngle']; } else { node['position']['t'] = this['rootAngle']; } this.incrementBranchWeight(); this.updateChildren(); return node; }; /* * Updates target positions for a set of child nodes any time the set * of child nodes changes. */ this.updateChildren = function() { // for each child node, calculate a new target for ( var i=0; i