New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

multilayerlayout3d

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multilayerlayout3d - npm Package Compare versions

Comparing version 0.1.1 to 0.1.3

111

lib/multilayerlayout3d.js

@@ -21,5 +21,6 @@ /*

var eventify = require('ngraph.events');
var Options = {
interLayerDistance: 100
};
/*

@@ -29,3 +30,3 @@ * Public Methods

function createLayout(graph, physicsSettings) {
function createLayout(graph, physicsSettings, options) {
if (!graph) {

@@ -35,6 +36,16 @@ throw new Error('Graph structure cannot be undefined');

var createSimulator = require('ngraph.physics.simulator');
// Update Options file according to input
if (options) {
for (var key in options) {
if (options.hasOwnProperty(key)) {
Options[key] = options[key];
console.log(key + ': ' + Options[key]);
}
}
}
/**
* Create one simulator for each layer
*/
var createSimulator = require('ngraph.physics.simulator');
var physicsSimulators = [];

@@ -45,7 +56,3 @@ for (var i=0;i<graph.layers.length;i++) {

/**
* Distance between layers depends on number of layers
*/
var interLayerDistance = 20 * i;
var interLayerDistance = Options.interLayerDistance;
var nodeBodies = typeof Object.create === 'function' ? Object.create(null) : {};

@@ -72,2 +79,3 @@ var springs = {};

// Check if all simulators are stable
//console.log(stable);
for (i=0;i<stable.length;i++) {

@@ -90,3 +98,2 @@ if (!stable[i]) {

body.pos.z = layer * interLayerDistance;
//body.pos = new prims.Vector3d(body.pos.x, body.pos.y, z); //Why does this not work??
return body.pos;

@@ -139,2 +146,15 @@ },

getGraphWidth: function () {
var boxes = [];
var box;
var max = 0;
var t;
for (var i=0;i<physicsSimulators.length; i++) {
box = physicsSimulators[i].getBBox();
t = Math.max(Math.abs(box.x1 - box.x2), Math.abs(box.y1 - box.y2));
if (t > max) max = t;
}
return max;
},
/*

@@ -146,3 +166,4 @@ * Requests layout algorithm to pin/unpin node to its current position

pinNode: function (node, isPinned) {
var body = getInitializedBody(node.id);
body.isPinned = !!isPinned;
},

@@ -154,3 +175,3 @@

isNodePinned: function (node) {
return false;
return getInitializedBody(node.id).isPinned;
},

@@ -169,2 +190,9 @@

/**
* Sets the inter layer distance
*/
setInterLayerDistance: function (dist) {
interLayerDistance = dist;
},
/**
* Gets physical body for a given node id. If node is not found undefined

@@ -188,5 +216,14 @@ * value is returned.

*/
simulator: {}
simulator: {},
/**
* Update physics settings
*/
updatePhysics: updatePhysics,
makeStable: function () {
onStableChanged(true);
}
};

@@ -199,6 +236,10 @@

graph.on('changed', onGraphChanged);
physicsSimulators[0].on('stable', onStableChanged); //TODO: This is just a quick fix
for (var i=0;i<physicsSimulators.length;i++) {
physicsSimulators[i].on('stable', onStableChanged);
}
//physicsSimulators[0].on('stable', onStableChanged);
}
function onStableChanged(isStable) {
console.log('Stable has changed!');
api.fire('stable', isStable);

@@ -252,3 +293,3 @@ }

var node = graph.getNode(nodeId);
return graph.layers.indexOf(node.data.layer.attributes.id); // Return the index of the layer of node
return graph.layers.indexOf(node.data.get('layer').get('id')); // Return the index of the layer of node
}

@@ -284,3 +325,8 @@

//TODO: Missing pinned nodes - necessary?
if (isNodeOriginallyPinned(node)) {
body.isPinned = true;
}
//TODO: Does this work??
}

@@ -309,3 +355,3 @@

// Only add springs for intra-layer links
var layer = graph.getNode(link.toId).data.layer.attributes.id; // One node is enough to get layer
var layer = graph.getNode(link.toId).data.get('layer').get('id'); // One node is enough to get layer
var layerindex = getLayer(link.toId);

@@ -337,2 +383,14 @@ if (checkLinkLayer(graph.getNode(link.fromId), graph.getNode(link.toId), layer)) {

/**
* Checks whether graph node has in its settings pinned attribute,
* which means layout algorithm cannot move it. Node can be preconfigured
* as pinned, if it has "isPinned" attribute, or when node.data has it.
*
* @param {Object} node a graph node to check
* @return {Boolean} true if node should be treated as pinned; false otherwise.
*/
function isNodeOriginallyPinned(node) {
return (node && (node.isPinned || (node.data && node.data.isPinned)));
}
function getInitializedBody(nodeId) {

@@ -380,3 +438,3 @@ var body = nodeBodies[nodeId];

function checkLinkLayer(node1, node2, layer) {
return node1.data.layer.attributes.id == layer && node2.data.layer.attributes.id == layer;
return node1.data.get('layer').get('id') == layer && node2.data.get('layer').get('id') == layer;
}

@@ -401,2 +459,19 @@

function updatePhysics(settings) {
for (key in settings) {
if (settings.hasOwnProperty(key)) {
for (var i = 0; i < physicsSimulators.length; i++) {
if (physicsSimulators[i][key]) {
physicsSimulators[i][key](settings[key]);
}
}
}
}
for (i = 0; i < physicsSimulators.length; i++) {
physicsSimulators[i].fire('stable', false);
physicsSimulators[i].step();
}
}
}

@@ -403,0 +478,0 @@

6

package.json
{
"name": "multilayerlayout3d",
"description": "A multilayer layout for ngraph.three",
"version": "0.1.1",
"version": "0.1.3",
"homepage": "https://github.com/DennisSchwartz/multilayerlayout3d",

@@ -33,4 +33,4 @@ "author": {

"dependencies": {
"ngraph.events": "0.0.3",
"ngraph.physics.simulator": "0.0.12"
"ngraph.events": "^0.0.3",
"ngraph.physics.simulator": "^0.0.12"
},

@@ -37,0 +37,0 @@ "devDependencies": {

@@ -30,3 +30,22 @@ # Multilayerlayout3d [![Build Status](https://secure.travis-ci.org/DennisSchwartz/multilayerlayout3d.png?branch=master)](http://travis-ci.org/DennisSchwartz/multilayerlayout3d) [![NPM version](https://badge-me.herokuapp.com/api/npm/multilayerlayout3d.png)](http://badges.enytc.com/for/npm/multilayerlayout3d)

You can also specify the distance between layers in the options, passed as an additional input value/
```javascript
/*
Set options
*/
var options = {
interLayerDistance: 100
};
/*
Initialize ngraph.three
*/
var graphics = nthree(this.graph, {
container: document.body,
layout: mplexLayout(this.graph, physicsSettings, options)
});
```
## Contributing

@@ -33,0 +52,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc