【问题标题】:tips.hide() function. Potential bug in infoVis/JIT?Tips.hide() 函数。 infoVis/JIT 中的潜在错误?
【发布时间】:2013-03-26 16:35:57
【问题描述】:

我有一个启用了“提示”的力导向图。我不想为那些隐藏的节点显示提示,即“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 时,我发现了一些看起来像错误的东西。下面是基本上将 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';
  }

如您所见,onShow 函数是从 onMouseMove 函数调用的。在 onShow 之后,调用 setTooltipPosition 函数将 style.display 设置回 ' '(参见我在代码中的注释)。因此,即使从 onShow 函数调用 hide(),提示也不会被隐藏。 当我在 setTooltipPosition 中注释掉该行时,它起作用了,即对于隐藏的节点,工具提示被隐藏了。

这是 infovis 中的错误还是我做错了什么。我想知道如果不是错误,应该如何使用隐藏功能。

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

【问题讨论】:

    标签: javascript data-visualization graph-visualization infovis thejit


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-31
      • 2017-01-02
      • 2012-07-17
      • 2013-05-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多