cytoscape.js 未导入样式
cytoscape.js not importing style
我使用 cytoscape.js 2.7.5 显示由 Cytoscape Desktop 导出为 graph.cyjs 并转换为包含 "var graph = ... the content of the cyjs file ...;"
的 Javascript 文件 graph.js 的图形。使用以下 HTML 我看到了节点和边缘,但未导入样式(颜色,用作节点名称的属性)。我怎样才能导入样式?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="cytoscape.js"></script>
<script src="graph.js"></script>
</head>
<body>
<div id="cy" style="width:100%;height:100vh;"></div>
<script>
var cy = cytoscape({
container: document.getElementById('cy') // container to render in
});
cy.add(graph.elements);
</script>
</body>
</html>
显然,Cytoscape Desktop 不会在其 .csjs 文件中保存样式信息,因此必须单独导出和导入:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="cytoscape.js"></script>
<script src="graph.js"></script>
<script src="style.js"></script>
</head>
<body>
<div id="cy" style="width:100%;height:100vh;"></div>
<script>
var cy = cytoscape({
container: document.getElementById('cy'),
style: style[0].style
});
cy.add(graph.elements);
</script>
</body>
</html>
我使用 cytoscape.js 2.7.5 显示由 Cytoscape Desktop 导出为 graph.cyjs 并转换为包含 "var graph = ... the content of the cyjs file ...;"
的 Javascript 文件 graph.js 的图形。使用以下 HTML 我看到了节点和边缘,但未导入样式(颜色,用作节点名称的属性)。我怎样才能导入样式?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="cytoscape.js"></script>
<script src="graph.js"></script>
</head>
<body>
<div id="cy" style="width:100%;height:100vh;"></div>
<script>
var cy = cytoscape({
container: document.getElementById('cy') // container to render in
});
cy.add(graph.elements);
</script>
</body>
</html>
显然,Cytoscape Desktop 不会在其 .csjs 文件中保存样式信息,因此必须单独导出和导入:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="cytoscape.js"></script>
<script src="graph.js"></script>
<script src="style.js"></script>
</head>
<body>
<div id="cy" style="width:100%;height:100vh;"></div>
<script>
var cy = cytoscape({
container: document.getElementById('cy'),
style: style[0].style
});
cy.add(graph.elements);
</script>
</body>
</html>