gpt4 book ai didi

javascript - 细胞景观中的边缘可以有多种颜色吗

转载 作者:行者123 更新时间:2023-12-04 10:53:28 27 4
gpt4 key购买 nike

我正在尝试创建具有多种颜色的边缘,不知道如何去做。
理想情况下,链接的每一半都会独立更新它们的颜色。

想知道这是否可行。
非常感谢
:)

最佳答案

看起来是的!查询 https://js.cytoscape.org/#style/edge-linehttps://js.cytoscape.org/#style/gradient .

策略是将线条渐变分成颜色停止位置,每个位置都有一个相关的颜色,如下所示:

var cy = (window.cy = cytoscape({
container: document.getElementById("cy"),
boxSelectionEnabled: false,
autounselectify: true,

style: [{
selector: "node",
css: {
"label": "data(id)",
"text-valign": "center",
"text-halign": "center",
"background-color": "data(faveColor)"
}
},
{
selector: "edge",
css: {
"line-fill": "radial-gradient",
"line-gradient-stop-colors": "red green blue",
"line-gradient-stop-positions": "25 50 75"
}
}
],
elements: {
nodes: [{
data: {
id: "a",
faveColor: "#2763c4"
}
},
{
data: {
id: "b",
faveColor: "#37a32d"
}
},
{
data: {
id: "c",
faveColor: "#37a32d"
}
}
],
edges: [{
data: {
source: "a",
target: "b"
}
},
{
data: {
source: "a",
target: "c"
}
}
]
},
layout: {
name: "dagre"
}
}));

cy.ready(function() {
cy.dblclick();
});

var nid = 0;
cy.bind('dblclick', function(evt) {
console.log('dblclick');
cy.add({
group: 'nodes',
data: {
id: nid,
faveColor: 'red'
},
position: {
x: evt.x,
y: evt.y
}
});
nid++;
});

cy.bind('click', 'node', function(evt) {
console.log('node clicked: ', evt.target.id());
});
body {
font: 14px helvetica neue, helvetica, arial, sans-serif;
}

#cy {
height: 100%;
width: 100%;
float: right;
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.3.0/dist/cytoscape.min.js">
</script>
<!-- cyposcape dagre -->
<script src="https://unpkg.com/dagre@0.7.4/dist/dagre.js"></script>
<script src="https://cdn.rawgit.com/cytoscape/cytoscape.js-dagre/1.5.0/cytoscape-dagre.js"></script>
<script src="https://unpkg.com/cytoscape-dblclick/dist/index.js"></script>
</head>

<body>
<div id="cy"></div>
</body>

</html>

关于javascript - 细胞景观中的边缘可以有多种颜色吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59350336/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com