anvaka / ngraph.forcelayout

Force directed graph layout
https://anvaka.github.io/ngraph.forcelayout/
BSD 3-Clause "New" or "Revised" License
169 stars 33 forks source link

defaultNodeMass returns NaN #18

Open hillar opened 3 years ago

hillar commented 3 years ago

defaultNodeMass returns NaN and Node mass should be a number is thrown

https://github.com/anvaka/ngraph.forcelayout/blob/f1c47b57035869750a9bfbe9336dee63eba1e90d/index.js#L388

seems that links does not have length but size, as newer graph.getLinks does not return array anymore

as a temporary workaround nodeMass function in physicsSettings helps..

nodeMass : (nodeId) => {
  const links = graph.getLinks(nodeId);
  if (links && links.length) return 1 + links.length / 3.0;
  else if (links && links.size) return 1 + links.size / 3.0;
  else return 1
  }
anvaka commented 3 years ago

Interesting. What version of the ngraph.graph are you using? I have changed that package but haven't published to npm yet, so that the links storage is different there (moved from array to set).

hillar commented 3 years ago

"ngraph.graph": "git+https://github.com/anvaka/ngraph.graph.git#c98822ccc4d9ffb7c1ed5d834a640a19f3a57531",