Cytoscape.js:样式不适用
Cytoscape.js: style doesn't apply
我在 Ember 应用程序中使用 Cytoscape.js。我为图形创建了一个组件。我尝试在组件的 didInsertElement
函数中设置图形样式表,如下所示:
this.get("cy").style()
.selector('node')
.css({
'width': '100px',
'height': '100px',
'border-color': 'gray',
'border-width': 3,
'border-opacity': 0.5
})
// unimportant code here
.selector('.faded')
.css({
'opacity': 0.0,
'text-opacity': 0
}).update();
当我在 Ember 中使用此组件访问路由时,未应用样式(但布局和其他功能正常工作)。当我转换到另一条路线然后又返回时,风格神奇地出现了。
我做错了什么?如何在 "first load" 上应用样式?
编辑:可以找到完整代码here
车把代码很简单:
<div class="container content-section" id="graph-content">
<div class="centre" style="margin: 10px">
<!-- cytoscape graph -->
<div id="cy"></div>
</div>
问题已解决 - 这是我的错误。 node的样式基于category
,属于node,异步加载。当我将节点插入图中时,节点承诺已经填满,但是嵌套关系尚未填满,因此节点样式为 undefined
.
我在 Ember 应用程序中使用 Cytoscape.js。我为图形创建了一个组件。我尝试在组件的 didInsertElement
函数中设置图形样式表,如下所示:
this.get("cy").style()
.selector('node')
.css({
'width': '100px',
'height': '100px',
'border-color': 'gray',
'border-width': 3,
'border-opacity': 0.5
})
// unimportant code here
.selector('.faded')
.css({
'opacity': 0.0,
'text-opacity': 0
}).update();
当我在 Ember 中使用此组件访问路由时,未应用样式(但布局和其他功能正常工作)。当我转换到另一条路线然后又返回时,风格神奇地出现了。
我做错了什么?如何在 "first load" 上应用样式?
编辑:可以找到完整代码here 车把代码很简单:
<div class="container content-section" id="graph-content">
<div class="centre" style="margin: 10px">
<!-- cytoscape graph -->
<div id="cy"></div>
</div>
问题已解决 - 这是我的错误。 node的样式基于category
,属于node,异步加载。当我将节点插入图中时,节点承诺已经填满,但是嵌套关系尚未填满,因此节点样式为 undefined
.