basant307/AI_Governance_Project
048
1var FDLayoutNode = require('layout-base').FDLayoutNode;2var IMath = require('layout-base').IMath;3 4function CoSENode(gm, loc, size, vNode) {5 FDLayoutNode.call(this, gm, loc, size, vNode);6}7 8 9CoSENode.prototype = Object.create(FDLayoutNode.prototype);10for (var prop in FDLayoutNode) {11 CoSENode[prop] = FDLayoutNode[prop];12}13 14CoSENode.prototype.move = function ()15{16 var layout = this.graphManager.getLayout();17 this.displacementX = layout.coolingFactor *18 (this.springForceX + this.repulsionForceX + this.gravitationForceX) / this.noOfChildren;19 this.displacementY = layout.coolingFactor *20 (this.springForceY + this.repulsionForceY + this.gravitationForceY) / this.noOfChildren;21 22 23 if (Math.abs(this.displacementX) > layout.coolingFactor * layout.maxNodeDisplacement)24 {25 this.displacementX = layout.coolingFactor * layout.maxNodeDisplacement *26 IMath.sign(this.displacementX);27 }28 29 if (Math.abs(this.displacementY) > layout.coolingFactor * layout.maxNodeDisplacement)30 {31 this.displacementY = layout.coolingFactor * layout.maxNodeDisplacement *32 IMath.sign(this.displacementY);33 }34 35 // a simple node, just move it36 if (this.child == null)37 {38 this.moveBy(this.displacementX, this.displacementY);39 }40 // an empty compound node, again just move it41 else if (this.child.getNodes().length == 0)42 {43 this.moveBy(this.displacementX, this.displacementY);44 }45 // non-empty compound node, propogate movement to children as well46 else47 {48 this.propogateDisplacementToChildren(this.displacementX,49 this.displacementY);50 }51 52 layout.totalDisplacement +=53 Math.abs(this.displacementX) + Math.abs(this.displacementY);54 55 this.springForceX = 0;56 this.springForceY = 0;57 this.repulsionForceX = 0;58 this.repulsionForceY = 0;59 this.gravitationForceX = 0;60 this.gravitationForceY = 0;61 this.displacementX = 0;62 this.displacementY = 0;63};64 65CoSENode.prototype.propogateDisplacementToChildren = function (dX, dY)66{67 var nodes = this.getChild().getNodes();68 var node;69 for (var i = 0; i < nodes.length; i++)70 {71 node = nodes[i];72 if (node.getChild() == null)73 {74 node.moveBy(dX, dY);75 node.displacementX += dX;76 node.displacementY += dY;77 }78 else79 {80 node.propogateDisplacementToChildren(dX, dY);81 }82 }83};84 85CoSENode.prototype.setPred1 = function (pred1)86{87 this.pred1 = pred1;88};89 90CoSENode.prototype.getPred1 = function ()91{92 return pred1;93};94 95CoSENode.prototype.getPred2 = function ()96{97 return pred2;98};99 100CoSENode.prototype.setNext = function (next)101{102 this.next = next;103};104 105CoSENode.prototype.getNext = function ()106{107 return next;108};109 110CoSENode.prototype.setProcessed = function (processed)111{112 this.processed = processed;113};114 115CoSENode.prototype.isProcessed = function ()116{117 return processed;118};119 120module.exports = CoSENode;121 