Skip to content
maxkfranz edited this page May 1, 2012 · 4 revisions

Core extensions specification

Introduction

Core extensions are a way of adding function to the core Cytoscape Web object, denoted in the documentation as cy. It's a great way of adding domain-specific code to Cytoscape Web.

For example, you may want to have a function in the core that calculates a score of graphs that contain protein-protein interactions. Not everyone using Cytoscape Web would want this function — not everyone using Cytoscape Web uses it for biological graphs &mdash which makes it an excellent candidate as a core extension.

You must register core extensions before you create an instance of Cytoscape Web that uses the extension. Otherwise, the function you define will not exist in that instance.

Defining a core extension

You define a core extension much in the same way you define most extensions. The difference is that &mdash unlike for renderers or layouts — a function definition is specified instead of an object prototype.

The pattern is as follows:

$.cytoscapeweb("core", "someFunctionName", function(){
  // this function is the definition of cy.someFunctionName
});

Here is a simple extension that calculates the number of nodes in the graph with a given selector.

(function($){
  $.cytoscapeweb("core", "number", function( selector ){
    var cy = this;

    return cy.elements( selector ).size();
  });
})( jQuery );

We can then use this function as normal in our application code.

// some time after creating an instance of Cytoscape Web

console.log( "We have this many nodes: %s", cy.number("node") );

Clone this wiki locally