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