cytoscape-automove
Advanced tools
Comparing version 1.9.0 to 1.10.0
@@ -185,3 +185,7 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
} 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 { | ||
@@ -256,2 +260,32 @@ return r; | ||
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) { | ||
@@ -583,2 +617,4 @@ return function (node) { | ||
// - { 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 | ||
@@ -585,0 +621,0 @@ // - 'viewport' => keeps the node body within the viewport |
{ | ||
"name": "cytoscape-automove", | ||
"version": "1.9.0", | ||
"version": "1.10.0", | ||
"description": "An extension for Cytoscape.js that automatically updates node positions based on specified rules", | ||
@@ -13,3 +13,3 @@ "main": "cytoscape-automove.js", | ||
"gh-pages:demo": "cpy demo.html . --rename=index.html", | ||
"gh-pages:deploy": "gh-pages -d .", | ||
"gh-pages:deploy": "gh-pages -d . -v node_modules/**", | ||
"gh-pages:clean": "rimraf index.html", | ||
@@ -16,0 +16,0 @@ "copyright": "update license", |
@@ -74,2 +74,4 @@ cytoscape-automove | ||
// - { 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 | ||
@@ -76,0 +78,0 @@ // - 'viewport' => keeps the node body within the viewport |
@@ -82,3 +82,8 @@ let defaults = require('./defaults'); | ||
} 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 { | ||
@@ -153,2 +158,32 @@ return r; | ||
let constrainOut = function( val, min, max ){ | ||
let mid = ( min + max ) / 2; | ||
if( val > min && val < max ){ | ||
return val > mid ? max : min; | ||
} | ||
return val; | ||
}; | ||
let constrainOutsideBox = function( node, bb ){ | ||
let pos = node.position(); | ||
let x = constrainOut( pos.x, bb.x1, bb.x2 ); | ||
let 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; | ||
}; | ||
let outsideBoxPosition = function( bb ){ | ||
return function( node ){ | ||
return constrainOutsideBox( node, bb ); | ||
}; | ||
}; | ||
let viewportPosition = function( cy ){ | ||
@@ -155,0 +190,0 @@ return function( node ){ |
@@ -13,2 +13,4 @@ | ||
// - { 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 | ||
@@ -15,0 +17,0 @@ // - 'viewport' => keeps the node body within the viewport |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51396
1034
176