首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >tips.hide()函数。infoVis/JIT中潜在的bug?

tips.hide()函数。infoVis/JIT中潜在的bug?
EN

Stack Overflow用户
提问于 2013-04-04 22:24:58
回答 1查看 529关注 0票数 2

我有一个力定向图,启用了“提示”。我不想显示隐藏节点的提示,也就是"alpha“为零的节点。在onShow回调函数中,我尝试使用tips.hide(),但它没有隐藏提示。这是我的代码。

代码语言:javascript
复制
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”。

代码语言:javascript
复制
  hide: function(triggerCallback) {
    this.tip.style.display = 'none';
    triggerCallback && this.config.onHide();
  }

现在看看下面的代码。

代码语言:javascript
复制
  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,还是我做错了什么。我想知道如何隐藏函数应该如何使用,如果它不是一个错误。

另外,有没有人知道其他更好的隐藏工具提示的方法?

EN

回答 1

Stack Overflow用户

发布于 2014-03-26 08:22:22

我也遇到过类似的问题。解决方案是使用.css('visibility','visible')而不是.hide() --因为元素在开始使用css样式时是隐藏的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15813990

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档