是cytoscapeweb 2的新手,我正在关注其中一个提供的示例,以了解如何使用API。 我无法使其工作,并且firebug报告以下消息:
组件返回失败代码: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;
}
});
我是否错过了一些明显的东西?
如果是这样,所有道歉。
答案 0 :(得分:3)
(1)即使在测试时,也不要在代码中添加警报。它可以破坏异步代码,例如初始化Cytoscape Web或进行AJAX调用。请改用console.log()
。
(2)您可能正在使用选项卡隐藏Cytoscape Web div cy
。您不应该使用display: none;
,因为Cytoscape Web视口将是0x0 px。尝试使用类似position: absolute; left: -9999px;
或类似隐藏的内容。这需要修改jQuery用于隐藏选项卡的任何类名(可能是.ui-state-hidden
或类似的东西)。
(3)我将研究使渲染器代码更能容忍隐藏的Cytoscape Web div。