初始化Cytoscape的(Initializing cytoscape)

2019-09-17 11:55发布

作为新cytoscapeweb 2,我下面,以了解如何使用API​​提供的示例之一。 我不能让它工作,萤火报告以下信息:

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

我的html文件中,该cytoscapeweb DIV嵌入在一个jQuery标签控件(只需提供上下文)

某处my.html

<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

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;
    }
});

我错过了一些东西明显?

如果是这样,所有的道歉。

Answer 1:

(1)不要把警报在你的代码一样,即使你正在测试。 它可以打破异步代码,如初始化Cytoscape的网页或做一个AJAX调用。 使用console.log()代替。

(2)你可能隐藏Cytoscape的网页DIV, cy ,与标签。 你不应该使用display: none; ,因为网络的Cytoscape视届时可为0x0像素。 尝试类似position: absolute; left: -9999px; position: absolute; left: -9999px; 或similiar隐蔽性。 这需要修改任何类名jQuery使用隐藏的标签(可能.ui-state-hidden或类似的东西)。

(3)我会考虑做渲染代码更宽容隐藏的Cytoscape网络的div。



Answer 2:

我有更好的办法解决这个问题:执行jQuery的选项卡所有的图表都加载之后。 http://cytoscape.github.io/cytoscape.js/#core/events/cy.ready

    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();           
           }
       });
    }


文章来源: Initializing cytoscape