cytoscape / cytoscape.js

Graph theory (network) library for visualisation and analysis
https://js.cytoscape.org
MIT License
10.09k stars 1.64k forks source link

First Node position stays at 0,0 #1235

Closed louisgv closed 7 years ago

louisgv commented 8 years ago

Hi,

I initialized my graph like so:

  console.log(u_gp.longitude());
  var cy = cytoscape({
    elements: [{ // User position node
      data: { // element data (put dev data here)
        id: 'user', // mandatory for each element
        weight: 0
      },
      position: { // the model position of the node (optional on init, mandatory after)
        x: u_gp.longitude(),
        y: u_gp.latitude()
      }
    }]
  });
...

  console.log(cy.json()
      .elements);

The first console.log shown that the u_gp does return the position correctly. The final log output shown that the position of the user stays at 0:

data: {
id: "user",
weight: 0
},
position: {
x: 0,
y: 0
},
group: "nodes",
removed: false,
selected: false,
selectable: true,
locked: false,
grabbable: true,
classes: ""
},

Did I do something wrong? How do I specify the position of the starting node? Thanks!

louisgv commented 8 years ago

Work around:

  var cy = cytoscape();

  cy.add({
    data: {
      id: 'user',
      weight: 0
    },
    position: { // the model position of the node (optional on init, mandatory after)
      x: u_gp.longitude(),
      y: u_gp.latitude()
    }
  });
maxkfranz commented 8 years ago

I've confirmed that the positions are set properly when using the preset layout at init. Are you sure you're setting a valid position and that you don't have any race conditions?