我是cytoscape的新手,我已经阅读了文档,但找不到有帮助的东西。在Cytoscape.js中有没有办法制作这样的东西(加权图)?:

我只需要知道如何显示边缘的权重。
到目前为止,我有这样的想法:
elements: [
// list of graph elements to start with
{
// node a
data: { id: "a" },
},
{
// node b
data: { id: "b" },
},
{
// edge ab
data: { id: "ab", weight: 3, source: "a", target: "b" },
},
],但是,将权重添加到边不会在图形中显示权重:

发布于 2020-09-24 14:00:53
您可以在边缘的css中使用'label': 'data(weight)'来将weight属性显示为边缘的标签。您还可以将此标签的样式调整为详细的here。我在下面的示例中应用了其中的两个(text- below y和text-orientation)。
var cy = window.cy = cytoscape({
container: document.getElementById('cy'),
layout: {name: 'grid', rows: 2},
style: [{
selector: 'node',
css: {
'content': 'data(id)',
'text-valign': 'center',
'text-halign': 'center'
}
},
{
selector: 'edge',
css: {
'label': 'data(weight)',
'text-margin-y': 15,
'text-rotation': 'autorotate'
}
}
],
elements: {
nodes: [{
data: {
id: 'n0'
}
},
{
data: {
id: 'n1'
}
},
{
data: {
id: 'n2'
}
},
{
data: {
id: 'n3'
}
}
],
edges: [{
data: {
id: 'n0n1',
source: 'n0',
target: 'n1',
weight: 3
}
},
{
data: {
id: 'n1n2',
source: 'n1',
target: 'n2',
weight: 5
}
},
{
data: {
id: 'n2n3',
source: 'n2',
target: 'n3',
weight: 7
}
}
]
}
});body {
font: 14px helvetica neue, helvetica, arial, sans-serif;
}
#cy {
height: 95%;
width: 95%;
left: 0;
top: 0;
position: absolute;
}<html>
<head>
<meta charset=utf-8 />
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">
<script src="https://unpkg.com/cytoscape@3.10.0/dist/cytoscape.min.js">
</script>
</head>
<body>
<div id="cy"></div>
</body>
</html>
https://stackoverflow.com/questions/64038224
复制相似问题