首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >初始化细胞角

初始化细胞角
EN

Stack Overflow用户
提问于 2012-05-24 15:10:55
回答 2查看 1.3K关注 0票数 3

对于cytoscapeweb 2来说,我是新手,为了学习如何使用API,我正在学习一个提供的示例。我无法让它工作,而firebug报告了以下消息:

组件返回失败代码: 0x80004005 (NS_ERROR_FAILURE) var n= this.nodesGroup.getBBox();

在我的html文档中,cytoscapeweb div嵌入到jquery选项卡小部件中(只是为了提供上下文)。

在my.html的某处

代码语言:javascript
复制
<div id="tabs">
    <ul>
      <li><a href="#tabs-1">Interactors Selection</a></li>
      <li><a href="#tabs-2">Interactome Builder</a></li>      
    </ul>
    <div id="tabs-1">
      <p>Tab 1 content</p>
    </div>
    <div id="tabs-2">
      <p>Tab 2 content</p>
       <div id="cy"></div>
    </div>
 </div>

在foo.js中

代码语言:javascript
复制
function cytoscapeInit() {
    alert ("intializing cytoscape");

    // create a mapper for node size
    var nodeSizeMapper = {
        continuousMapper: {
            attr: {
                name: "weight",
                min: 0,
                max: 100
            },
            mapped: {
                min: 15,
                max: 30
            }
        }
    };
 // call cytoscape web on the `cy` div
    $("#cy").cytoscapeweb({
                              // define the elements in the graph
    elements: {
        nodes: [
            { data: { id: "a", weight: 43 }, classes: "foo" },
            { data: { id: "b", weight: 2 }, classes: "bar" },
            { data: { id: "c", weight: 88 }, classes: "foo bar" }
        ],

        edges: [
            { data: { id: "ab", source: "a", target: "b", weight: 32 }, classes: "foo" },
            { data: { id: "bc", source: "b", target: "c", weight: 12 }, classes: "bar baz" },
            { data: { id: "ca", source: "c", target: "a", weight: 96 }, classes: "baz foo" },
            { data: { id: "ac", source: "a", target: "c", weight: 65 }, classes: "bar" }
        ]
    },

    // define the layout to use
    layout: {
        name: "preset",
        positions: {
            "a": { x: 30, y: 30 },
            "b": { x: 125, y: 131 },
            "c": { x: 200, y: 50 } 
        },
        fit: false,
        stop: function(){
            cy.reset();
            cy.center();
        }
    },

    // define the visual style (like css) of the graph
    style: {
        selectors: {
            "node":{
                shape: "ellipse",
                fillColor: "#888",
                height: nodeSizeMapper,
                width: nodeSizeMapper,
                labelText: {
                    passthroughMapper: "id"
                }
            },
            ".yay": {
                fillColor: "red",
                lineColor: "red",
                targetArrowColor: "red"
            },
            "edge": {
                lineColor: "#ccc",
                targetArrowColor: "#ccc",
                width: {
                    continuousMapper: {
                        attr: {
                            name: "weight"
                        },
                        mapped: {
                            min: 2,
                            max: 5
                        }
                    }
                },
                targetArrowShape: "triangle"
            },
            "node:selected": {
                fillColor: "#333"
            },
            "edge:selected":{
                lineColor: "#666",
                targetArrowColor: "#666"
            }
        }
    },

    // define the callback for when cytoscape web is ready
    ready: function( cy ){
        window.cy = cy;
    }
});

我错过什么明显的东西了吗?

如果是的话,请全部道歉。

EN

回答 2

Stack Overflow用户

发布于 2012-05-28 14:58:09

(1)即使在测试时,也不要像这样在代码中添加警报。它可以破坏异步代码,比如初始化Cytoscape或执行AJAX调用。使用console.log()代替。

(2)您可能隐藏了带有选项卡的Cytoscape,cy。您不应该使用display: none;,因为这时Cytoscape将是0x0px。尝试一些类似position: absolute; left: -9999px;或相似的东西来隐藏。这需要修改jQuery用于隐藏选项卡的类名(可能是.ui-state-hidden或类似的名称)。

(3)我将研究如何使渲染器代码更能容忍隐藏的Cytoscape。

票数 3
EN

Stack Overflow用户

发布于 2015-09-10 14:54:51

对于这个问题,我有一个更好的解决方案:在加载所有图形之后执行jquery选项卡。http://cytoscape.github.io/cytoscape.js/#core/events/cy.ready

代码语言:javascript
复制
    for(var t = 0, tot=pageList.length; t<tot; t++) //draw graph for all pages
    {           
        var currPage = pageList[t];
        getData(currPage);
    } 

    function getData(currPage)
    {
       //initiate graph, do stuff...

       //graph ready
       window[currPage + "Container"].ready(function(e)
       {    
           if (currPage.indexOf(lastPage) != -1)//executetabsafterlastgraphisdrawn  
           {
               setTabs();           
           }
       });
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10740269

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档