gpt4 book ai didi

javascript - Cytoscape JS 和 Angular8 的工具提示

转载 作者:行者123 更新时间:2023-11-30 13:48:05 24 4
gpt4 key购买 nike

我正在寻找将鼠标悬停在 Cytoscape 图中的节点上时显示工具提示的示例。我看过几个 popperjs 和 qtip 的例子,但没有一个在工作(至少对我而言)

cytoscape-qtip 似乎已被弃用

此处示例 (Tippy.js)

https://github.com/cytoscape/cytoscape.js-popper

好像不行

最佳答案

您可以使用 here 中的代码很好,我自己做了一些调整,以便工具提示出现在悬停时:

document.addEventListener("DOMContentLoaded", function() {
var cy = (window.cy = cytoscape({
container: document.getElementById("cy"),
style: [{
selector: "node",
style: {
content: "data(id)"
}
},
{
selector: "edge",
style: {
"curve-style": "bezier",
"target-arrow-shape": "triangle"
}
}
],
elements: {
nodes: [{
data: {
id: "a"
}
}, {
data: {
id: "b"
}
}],
edges: [{
data: {
id: "ab",
source: "a",
target: "b"
}
}]
},
layout: {
name: "grid"
}
}));

function makePopper(ele) {
let ref = ele.popperRef(); // used only for positioning

ele.tippy = tippy(ref, {
// tippy options:
content: () => {
let content = document.createElement("div");

content.innerHTML = ele.id();

return content;
},
trigger: "manual" // probably want manual mode
});
}

cy.ready(function() {
cy.elements().forEach(function(ele) {
makePopper(ele);
});
});

cy.elements().unbind("mouseover");
cy.elements().bind("mouseover", event => event.target.tippy.show());

cy.elements().unbind("mouseout");
cy.elements().bind("mouseout", event => event.target.tippy.hide());
});
body {
font-family: helvetica neue, helvetica, liberation sans, arial, sans-serif;
font-size: 14px
}

#cy {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
z-index: 1;
}

h1 {
opacity: 0.5;
font-size: 1em;
font-weight: bold;
}
<head>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
<script src="https://unpkg.com/cytoscape/dist/cytoscape.min.js"></script>
<script src="https://unpkg.com/popper.js@1.14.7/dist/umd/popper.js"></script>
<script src="https://cdn.jsdelivr.net/npm/cytoscape-popper@1.0.4/cytoscape-popper.min.js"></script>
<script src="https://unpkg.com/tippy.js@4.0.1/umd/index.all.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/tippy.js@4.0.1/index.css" />
</head>

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

关于javascript - Cytoscape JS 和 Angular8 的工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58899397/

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