gpt4 book ai didi

graph - cytoscape js标签显示,如何换行文字

转载 作者:行者123 更新时间:2023-12-02 03:05:20 24 4
gpt4 key购买 nike

我正在使用 cytoscape.js 来显示有向图,并在标签中显示 2 个属性。

我想换行文本,文档中说这是可能的,但我无法让它工作。任何人都可以帮助语法吗?

'label': 'data(name)',
'font-size' : 14
'text-wrap': 'wrap/n'

text-wrap 好像不行,它挂断了图形显示。

我需要设置 'text-max-width' 吗?

提前致谢

最佳答案

你不能在 text-wrap css 属性中添加\n,你正在寻找 label 属性:

{
"selector": ".multiline-manual",
"style": {
"text-wrap": "wrap"
}
},

{
"selector": ".multiline-auto",
"style": {
"text-wrap": "wrap",
"text-max-width": 80
}
},

这些类中的一个应该添加到您希望标签被包装的节点。你可以这样做:

var cy = (window.cy = cytoscape({
container: document.getElementById("cy"),

boxSelectionEnabled: false,
autounselectify: true,

style: [{
selector: "node",
css: {
content: "data(name)",
height: "60px",
width: "60px"
}
},
{
selector: "edge",
css: {
"target-arrow-shape": "triangle"
}
},
{
selector: ".multiline-manual",
style: {
"text-wrap": "wrap"
}
},

{
selector: ".multiline-auto",
style: {
"text-wrap": "wrap",
"text-max-width": 80
}
}
],

elements: {
nodes: [{
data: {
id: "n0",
name: "This is a very long name and all I have to do is to add a class!"
},
classes: "multiline-auto"
},
{
data: {
id: "n1",
name: "Shorter"
},
classes: "multiline-auto"
},
{
data: {
id: "n2",
name: "This shouldn't wrap"
},
classes: "multiline-manual"
},
{
data: {
id: "n3",
name: "This should\nwrap"
},
classes: "multiline-manual"
}
],
edges: [{
data: {
source: "n0",
target: "n1"
}
},
{
data: {
source: "n1",
target: "n2"
}
},
{
data: {
source: "n1",
target: "n3"
}
}
]
},

layout: {
name: "dagre",
padding: 5
}
}));
body {
font: 14px helvetica neue, helvetica, arial, sans-serif;
}

#cy {
height: 100%;
width: 100%;
left: 0;
top: 0;
float: left;
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>
<script src="https://unpkg.com/jquery@3.3.1/dist/jquery.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>
</head>

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

</html>

关于graph - cytoscape js标签显示,如何换行文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59155757/

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