Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Node mass should be a number #40

Open
AydinChavez opened this issue Mar 31, 2022 · 4 comments
Open

Error: Node mass should be a number #40

AydinChavez opened this issue Mar 31, 2022 · 4 comments

Comments

@AydinChavez
Copy link

AydinChavez commented Mar 31, 2022

Hi all,

when using this module as part of layouting the graph via

console.log('Loading graph');
var graph = require('./loadgraph.js')();
console.log('Loaded ' + graph.getNodesCount() + ' nodes; ' + graph.getLinksCount() + ' edges');

var createLayout = require('ngraph.offline.layout');
var layout = createLayout(graph);
console.log('Starting layout');
layout.run();

I get following error:

Loading graph
Loaded 79566 nodes; 255149 edges
/Users/aydin/Workspace/ngraph_native_suite/node_modules/ngraph.forcelayout/index.js:357
      throw new Error('Node mass should be a number')
      ^

Error: Node mass should be a number
    at updateBodyMass (/Users/aydin/Workspace/ngraph_native_suite/node_modules/ngraph.forcelayout/index.js:357:13)
    at initBody (/Users/aydin/Workspace/ngraph_native_suite/node_modules/ngraph.forcelayout/index.js:290:7)
    at /Users/aydin/Workspace/ngraph_native_suite/node_modules/ngraph.forcelayout/index.js:265:7
    at Object.forEachNode (/Users/aydin/Workspace/ngraph_native_suite/node_modules/ngraph.graph/index.js:543:11)
    at initPhysics (/Users/aydin/Workspace/ngraph_native_suite/node_modules/ngraph.forcelayout/index.js:264:11)
    at Function.createLayout [as get2dLayout] (/Users/aydin/Workspace/ngraph_native_suite/node_modules/ngraph.forcelayout/index.js:35:3)
    at createLayout (/Users/aydin/Workspace/ngraph_native_suite/node_modules/ngraph.forcelayout3d/index.js:21:23)
    at createLayout (/Users/aydin/Workspace/ngraph_native_suite/node_modules/ngraph.offline.layout/index.js:19:16)
    at Object.<anonymous> (/Users/aydin/Workspace/ngraph_native_suite/bin/layout.js:6:14)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)

Any idea how to fix this? This does not happen with ngraph-binary layouting (which had another unrelated sideffects in the result)

@dholth
Copy link

dholth commented Jun 27, 2022

I had this problem related to using newer ngraph.graph with the offline layout. Depending on the version of ngraph.graph .length or .size has to be used, when calculating mass

node_modules/ngraph.forcelayout/index.js: return 1 + (links.length || links.size) / 3.0;

@anvaka
Copy link
Owner

anvaka commented Jul 16, 2022

@dholth is correct.

Can you please run the following script to collect versions of your packages?

echo "ngraph.graph" && cat node_modules/ngraph.graph/package.json | grep version
echo "ngraph.offline.layout" && cat node_modules/ngraph.offline.layout/package.json | grep version
echo "ngraph.forcelayout3d" && cat node_modules/ngraph.forcelayout3d/package.json | grep version
echo "ngraph.forcelayout" && cat node_modules/ngraph.forcelayout/package.json | grep version

I do have checks in the current version of the library

var nodeMass = graph.version > 19 ? defaultSetNodeMass : defaultArrayNodeMass;
and trying my best to figure out the version, but something seem to be missing.

@AtomBoy
Copy link

AtomBoy commented Oct 14, 2022

I'm using the graph and forcelayout via unplug.com and I'm seeing the same error with the current versions. Using graph v 19.1.0 works.

graph is 20.0.1 and force layout is 3.3.1.

<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8" />
    <title>ngraph error</title>
    <!-- new version 20.1 of ngraph.graph has a bug when adding an edge. reverting to 19.1.0 for now. -->
    <!-- script src="https://unpkg.com/ngraph.graph@19.1.0/dist/ngraph.graph.min.js" --></script>
    <script src="https://unpkg.com/ngraph.graph/dist/ngraph.graph.min.js"></script>
    <script src="https://unpkg.com/ngraph.forcelayout/dist/ngraph.forcelayout.min.js"></script>
  </head>

  <body> See console </body>

  <script defer>
    let g = createGraph();
    let l = ngraphCreateLayout(g);
    g.addNode('a');
    g.addNode('b');
    g.addLink('a', 'b'); /* <-- Throws [Error] Error: Node mass should be a number
	updateBodyMass (ngraph.forcelayout.min.js:1:5124)
	initLink (ngraph.forcelayout.min.js:1:4480)
	onGraphChanged (ngraph.forcelayout.min.js:1:3346)
	fire (ngraph.graph.min.js:1:8685)
	exitModificationReal (ngraph.graph.min.js:1:6575)
	addLink (ngraph.graph.min.js:1:3826)
	Global Code (127.0.0.1:58)
  */
  </script>
</html>

Thanks for the terrific libraries!

@xela1601
Copy link

Hello @anvaka,
first of all thanks a lot for your awesome open source contributions. Really appreciate.

I do have checks in the current version of the library
[...]
and trying my best to figure out the version, but something seem to be missing.

I also had the same error and i think i know what is the issue:
the latest version of package ngraph.forcelayout3d (1.2.0) has dependency "ngraph.forcelayout": "^1.2.0".
In that version of ngraph.forcelayout the check and both functions defaultArrayNodeMass and defaultSetNodeMass were not yet implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants