Skip to content

Collection renderedPosition

maxkfranz edited this page Mar 8, 2012 · 5 revisions

node.renderedPosition()

Get or set the rendered position of a node or a collection of nodes.

node.renderedPosition()

Gets the rendered position object for this node

node.renderedPosition( dimension )

Gets the specified rendered dimension for the node

dimension : The name of the dimension value to get (e.g. "x")

nodes.renderedPosition( dimension, value )

Sets the value of the specified rendered dimension for all nodes in the collection

dimension : The name of the dimension value to set (e.g. "x")
value : The value of the dimension to set (e.g. 100)

nodes.renderedPosition( position )

Sets the the rendered position object for all nodes in the collection

position : The position object to set as the rendered position

Details

This function returns a position object if no arguments are specified.

Note that this function returns the rendered position rather than the model position. For the model position, see node.position(). This function is useful for positioning things on-screen relative to a node.

For collections, the rendered position of the first element in the collection is returned.

This function is useful for setting the on-screen position of a node. This function takes into account any prior zooming or panning for you. For example:

cy.nodes("#n0").renderedPosition({
  x: 0,
  y: 0
});

This sets the position of the node to the top-left of the Cytoscape Web panel, regardless of zooming or panning. It is important to note that the position set here — in this case (0, 0) — does not correspond to the model position. The model position is calculated for you such that the rendered position of the node is as you specify to nodes.renderedPosition().

Examples

Get the object:

cy.nodes("#n1").renderedPosition(); // e.g. { x: 125, y: 225 }

Get the x dimension:

cy.nodes("#n1").renderedPosition("x"); // e.g. 125

Clone this wiki locally