cytoscape.js with cola seems no longer to work

1.3k views Asked by At

I'm trying the latest cytoscape with the latest cola and I get the following error:

Uncaught TypeError: cola.adaptor is not a function

for the cytoscape.js code snippet:

   var adaptor = layout.adaptor = cola.adaptor({
    trigger: function( e ){ // on sim event
      switch( e.type ){
        case 'tick':
          if( options.animate ){

Did the API change for Cola?

3

There are 3 answers

0
Alexander Kaminskiy On

cola import if you use webpack for build app:

import cola from 'exports?cola!webcola/WebCola/cola';

that`s works for me :)

0
maxkfranz On

Cola now has good npm and versioning support, so you can easily try different versions of Cola if you have issues.

I've also made a pull request to Cola so they have a dedicated parent class, generic adapter in Typescript. The PR has since been merged in -- so it should be well supported into the future. (The previous adapter in Cola was a JS one, which apparently didn't fit well with their classical inheritance model in TS.)

--

Old answer:

Cola hasn't had support for semantic versioning, and it's unsupported in package managers. Updates to Cola regularly break API compatibility, and rewriting the Cytoscape.js side of things for an updated version of Cola is not an option until a future major version release.

Use the included version of Cola in the download ZIP for Cytoscape.js, if you want to guarantee compatibility.

You may also want to file an issue with Cola, as the issue in this case is certainly on that side and Cytoscape.js can't operate without a fix: https://github.com/tgdwyer/WebCola/issues

0
sighrobot On

I still get this error when trying to do as the docs suggest (React/Browserify/ES6/npm):

import cytoscape from 'cytoscape';
import cycola from 'cytoscape-cola';
import cola from 'webcola';

cycola(cytoscape, cola);

However I was able to make it work after seeing this issue and including the cola v3 script in the <head> of my index file.

Finally, I had to do this:

cycola(cytoscape, window.cola); // since cola now lives in window