简体   繁体   English

与可乐的cytoscape.js似乎不再工作

[英]cytoscape.js with cola seems no longer to work

I'm trying the latest cytoscape with the latest cola and I get the following error: 我正在使用最新的可乐尝试最新的cytoscape,我收到以下错误:

Uncaught TypeError: cola.adaptor is not a function 未捕获的TypeError:cola.adaptor不是函数

for the cytoscape.js code snippet: 对于cytoscape.js代码片段:

   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? API的API改变了吗?

I still get this error when trying to do as the docs suggest (React/Browserify/ES6/npm): 尝试按照文档建议(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. 但是,在看到此问题并在我的索引文件的<head>中包含cola v3脚本后,我能够使其工作。

Finally, I had to do this: 最后,我必须这样做:

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

Cola now has good npm and versioning support, so you can easily try different versions of Cola if you have issues. Cola现在具有良好的npm和版本支持,因此如果您遇到问题,可以轻松尝试不同版本的Cola。

I've also made a pull request to Cola so they have a dedicated parent class, generic adapter in Typescript. 我还向Cola提出了拉取请求,因此他们在Typescript中有一个专用的父类,通用适配器。 The PR has since been merged in -- so it should be well supported into the future. PR已经合并 ​​- 所以它应该得到很好的支持。 (The previous adapter in Cola was a JS one, which apparently didn't fit well with their classical inheritance model in TS.) (Cola中的前一个适配器是一个JS,它显然不适合TS中的经典继承模型。)

-- -

Old answer: 老答案:

Cola hasn't had support for semantic versioning, and it's unsupported in package managers. Cola没有支持语义版本控制,它在包管理器中不受支持。 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. 对Cola的更新会定期破坏API的兼容性,并且在未来的主要版本发布之前,为Cola的更新版本重写Cytoscape.js方面不是一个选择。

Use the included version of Cola in the download ZIP for Cytoscape.js, if you want to guarantee compatibility. 如果您想保证兼容性,请在下载ZIP for Cytoscape.js中使用附带的Cola版本。

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 你可能还想向Cola提出一个问题,因为在这种情况下肯定会出现问题,如果没有修复,Cytoscape.js就无法运行: https//github.com/tgdwyer/WebCola/issues

cola import if you use webpack for build app: 如果您使用webpack构建应用程序,可乐导入:

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

that`s works for me :) 那对我有用:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM