我有一个力定向图,启用了“提示”。我不想显示隐藏节点的提示,也就是"alpha“为零的节点。在onShow回调函数中,我尝试使用tips.hide(),但它没有隐藏提示。这是我的代码。
Tips: {
enable: true,
type: 'Native',
onShow: function(tip, node) {
if( node.getData('alpha') == 0 ) this.fd.tips.hide(false);
else tip.innerHTML = node.name;
}
}当我深入到infovis库jit.js时,我发现了一些看起来像是bug的东西。下面是hide函数,它基本上将style.display设置为“none”。
hide: function(triggerCallback) {
this.tip.style.display = 'none';
triggerCallback && this.config.onHide();
}现在看看下面的代码。
onMouseMove: function(e, win, opt) {
if(this.dom && this.isLabel(e, win)) {
this.setTooltipPosition($.event.getPos(e, win));
}
if(!this.dom) {
var node = opt.getNode();
if(!node) {
this.hide(true);
return;
}
if(this.config.force || !this.node || this.node.id != node.id) {
this.node = node;
this.config.onShow(this.tip, node, opt.getContains());
}
this.setTooltipPosition($.event.getPos(e, win));
}
},
setTooltipPosition: function(pos) {
var tip = this.tip,
style = tip.style,
cont = this.config;
style.display = ''; //This looks like a problem
//get window dimensions
var win = {
'height': document.body.clientHeight,
'width': document.body.clientWidth
};
//get tooltip dimensions
var obj = {
'width': tip.offsetWidth,
'height': tip.offsetHeight
};
//set tooltip position
var x = cont.offsetX, y = cont.offsetY;
style.top = ((pos.y + y + obj.height > win.height)?
(pos.y - obj.height - y) : pos.y + y) + 'px';
style.left = ((pos.x + obj.width + x > win.width)?
(pos.x - obj.width - x) : pos.x + x) + 'px';
}如您所见,从onMouseMove函数调用onShow函数。在onShow之后,将调用setTooltipPosition函数,该函数将style.display设置回‘’(参见代码中的注释)。因此,即使在从onShow函数调用hide()之后,提示也不会被隐藏。当我在setTooltipPosition中注释掉这一行时,它起作用了,即隐藏的节点的工具提示被隐藏。
这是infovis中的一个bug,还是我做错了什么。我想知道如何隐藏函数应该如何使用,如果它不是一个错误。
另外,有没有人知道其他更好的隐藏工具提示的方法?
发布于 2014-03-26 08:22:22
我也遇到过类似的问题。解决方案是使用.css('visibility','visible')而不是.hide() --因为元素在开始使用css样式时是隐藏的。
https://stackoverflow.com/questions/15813990
复制相似问题