Skip to content
maxkfranz edited this page May 14, 2012 · 21 revisions

A collection is an object that contains a set of elements. For the plain object used to create an element when loading a graph, see the plain element documentation.

Collection API documentation

You can access the collection API by getting a collection from the graph. You can get elements via the graph manipulation and accessor functions in the core object API.

Details

A collection contains a set of nodes and edges. Calling a function applies the function to all elements in the collection. When reading values from a collection, eles.data() for example, the value of the first element in the collection is returned. This follows the jQuery convention. For example:

// assume graph:
// n1[weight = 10], n2[weight = 60], n3[weight = 90]

var weight = cy.nodes().data("weight"); // returns 10

You can insure that you're reading from the element you want by using a selector to narrow down the collection to one element (i.e. eles.size() == 1) or the eles.eq() function.

Clone this wiki locally