data visualization - Get the coordinates of the nodes of a rendered graph in Sigma.js -


is possible coordinates of nodes of graph after it's rendered sigmajs ?

var sigma = require('sigma'); var i,     s,     n = 100,     e = 500,     g = {         nodes: [],         edges: []     };  // generate random graph: (i = 0; < n; i++)     g.nodes.push({         id: 'n' + i,         label: 'node ' + i,         x: math.random(),         y: math.random(),         size: math.random(),         color: '#666'     });  (i = 0; < e; i++)     g.edges.push({         id: 'e' + i,         source: 'n' + (math.random() * n | 0),         target: 'n' + (math.random() * n | 0),         size: math.random(),         color: '#ccc'     }); sigma.renderers.def = sigma.renderers.canvas; // instantiate sigma: s = new sigma({     graph: g,     container: document.getelementbyid('sigma-container'),     type: 'canvas' }); 

i want real coordinates (xs , ys) of nodes in graph. (after force atlas 2 applied on it)

you can real coordinates of nodes on events 'clicknode' event. here example code getting real coordinates on node click event.

s.bind('clicknode', function(e) {        console.log(e.data.captor);        /* result : { x:-333,  y:-138,  clientx:363, clienty:262, ctrlkey:false,   isdragging:false, metakey:false, shiftkey:false}  */  });

in argument 'e' passed in clicknode function, can data bounded particular node data related click event on canvas.

edit:

try using external json file , use sigma's external json parser sigma.parsers.json.js. provides callback function facility can real coordinates of nodes. find below code.

/*include plugins/sigma.parsers.json/sigma.parsers.json.js */  sigma.parsers.json('yourjsonfile.json', {      container: 'sigma-container',      type: 'canvas'    },        function(s){             s.graph.nodes().foreach(function(s) {      console.log(s); //result: "read_cam0:x" => x-coordinate ,"read_cam0:y" => y-coordinate          });}  );

like in events, in callback can data node on canvas , data bounded node.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -