crubier / react-graph-vis

A react component to render nice graphs using vis.js

Home Page:http://crubier.github.io/react-graph-vis/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Randomly generate xy based on edge 'distance' length?

jduncanRadBlue opened this issue · comments

After digging and playing around I am having a hard time trying to specify node placement. I have a distance value that corresponds to how far away I'd like the next node to be from the main node. Is there a way to randomly place the nodes on the graph but have the edge's a certain length? So lets say for example I have this:

const graph = {
  nodes: [
      {id: 1, label: 'Home'},
      {id: 2, label: 'Node 2'},  <---this guy has a distance of 1.0
      {id: 3, label: 'Node 3'},  <---this guy has a distance of 1.2      
      {id: 4, label: 'Node 4'},  <---this guy has a distance of 1.7
      {id: 5, label: 'Node 5'}   <---this guy has a distance of 2.1
    ],
  edges: [
      {from: 1, to: 2},
      {from: 1, to: 3},
      {from: 1, to: 4},
      {from: 1, to: 5}
    ]
}

Is there a way to auto generate Node x and y values based off of the distance attribute? I'm not finding anything that will allow for me to do this.
Thanks so much!!