gpt4 book ai didi

javascript - 为什么我的 Node 悬停弹出窗口在我的 vis.js 网络中不起作用?

转载 作者:行者123 更新时间:2023-11-30 08:26:16 24 4
gpt4 key购买 nike

我遇到了一个问题,尽管我的 Node 对象中包含“标题”属性,但当我将鼠标悬停在 Node 上时,没有显示包含标题内容的弹出窗口。

这是我的选择以及我如何设置我的网络。

setUpNetwork(){
let container = document.getElementById('mynetwork');
//These options dictate the dynamic of the network
let options = {
nodes: {
shape: 'box'
},
interaction: {
dragNodes: false,
dragView: false,
hover: true
},
layout: {
randomSeed: undefined,
improvedLayout: true,
hierarchical: {
enabled: true,
levelSeparation: 180,
nodeSpacing: 180,
edgeMinimization: true,
parentCentralization: true,
direction: 'UD', // UD, DU, LR, RL
sortMethod: 'directed' // hubsize, directed
}
},
physics: {
enabled: false
}
}
// initialize your network!
this.network = new vis.Network(container, this.data, options);
}

当我将一个 Node 添加到我的网络 Node 列表时,这是我的结构:

addNode(node: any){
try {
this.data.nodes.add({
id: node.id,
color: node.color,
title: node.title,
label: node.label
});
this.network.fit();
}
catch (err) {}
}

我运行代码的环境使得很难提供此问题的实时示例。网络中的其他一切都工作正常(标签、ID、颜色),只是当我将鼠标悬停在 Node 上时标题不正常。

编辑:

我从 this example 复制了这段代码来自弹出窗口工作的 vis.js。

// create an array with nodes
var nodes = new vis.DataSet([
{id: 1, label: 'Node 1', title: 'I have a popup!'},
{id: 2, label: 'Node 2', title: 'I have a popup!'},
{id: 3, label: 'Node 3', title: 'I have a popup!'},
{id: 4, label: 'Node 4', title: 'I have a popup!'},
{id: 5, label: 'Node 5', title: 'I have a popup!'}
]);

// create an array with edges
var edges = new vis.DataSet([
{from: 1, to: 3},
{from: 1, to: 2},
{from: 2, to: 4},
{from: 2, to: 5}
]);

// create a network
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
var options = {interaction:{hover:true}};
this.network = new vis.Network(container, data, options);

我尝试在我的环境中只使用它;但是,弹出窗口不会像示例中那样显示。我知道我的悬停事件有效,因为我包含了这段代码,当我悬停在一个 Node 上时打印到控制台:

this.network.on("showPopup", function (params) {
console.log("DO SOMETHING");
})

这里是否缺少某些选项设置?尽管在我的 Node 对象中包含“title”属性,但为什么我的悬停弹出窗口不显示,是否还有其他问题?

最佳答案

没有显示任何内容,因为您正在使用事件 on("showPopup")。你必须使用 on("hoverNode")。所以用

network.on("hoverNode", function(){
// functionality for popup to show on mouseover
});


network.on("blurNode", function(){
// functionality for popup to hide on mouseout
});

添加 Node 更好用

nodes.add()

关于javascript - 为什么我的 Node 悬停弹出窗口在我的 vis.js 网络中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45232460/

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