Skip to content

Commit

Permalink
Build for release
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkfranz committed Jul 12, 2018
1 parent 26c78c0 commit 270356f
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion cytoscape-automove.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ var getRepositioner = function getRepositioner(rule, cy) {
} else if (r === 'drag') {
return dragAlong(rule);
} else if (isObject(r)) {
return boxPosition(r);
if (r.type == undefined || r.type == "inside") {
return boxPosition(r);
} else if (r.type == "outside") {
return outsideBoxPosition(r);
}
} else {
return r;
}
Expand Down Expand Up @@ -252,6 +256,36 @@ var boxPosition = function boxPosition(bb) {
};
};

var constrainOut = function constrainOut(val, min, max) {
var mid = (min + max) / 2;
if (val > min && val < max) {
return val > mid ? max : min;
}
return val;
};

var constrainOutsideBox = function constrainOutsideBox(node, bb) {
var pos = node.position();
var x = constrainOut(pos.x, bb.x1, bb.x2);
var y = constrainOut(pos.y, bb.y1, bb.y2);

if (x != pos.x && y != pos.y) {
if (Math.abs(pos.x - x) < Math.abs(pos.y - y)) {
pos.x = x;
} else {
pos.y = y;
}
}

return pos;
};

var outsideBoxPosition = function outsideBoxPosition(bb) {
return function (node) {
return constrainOutsideBox(node, bb);
};
};

var viewportPosition = function viewportPosition(cy) {
return function (node) {
var extent = cy.extent();
Expand Down Expand Up @@ -578,6 +612,8 @@ var defaults = {
// specify how a node's position should be updated with one of
// - function( node ){ return { x: 1, y: 2 }; } => put the node where the function returns
// - { x1, y1, x2, y2 } => constrain the node position within the bounding box (in model co-ordinates)
// - { x1, y1, x2, y2, type: 'inside' } => constrain the node position within the bounding box (in model co-ordinates)
// - { x1, y1, x2, y2, type: 'outside' } => constrain the node position outside the bounding box (in model co-ordinates)
// - 'mean' => put the node in the average position of its neighbourhood
// - 'viewport' => keeps the node body within the viewport
// - 'drag' => matching nodes are effectively dragged along
Expand Down

0 comments on commit 270356f

Please sign in to comment.