2

I have a force directed graph with "Tips" enabled. I don't want to show tips for those nodes which are hidden i.e. for whom "alpha" is zero. In onShow call back function I am trying to use tips.hide() but it is not hiding the tip. Here is my code.

Tips: {  
  enable: true,  
  type: 'Native',  
  onShow: function(tip, node) { 
     if( node.getData('alpha') == 0 ) this.fd.tips.hide(false); 
     else tip.innerHTML = node.name;  
  }  
}

When I drilled down into infovis library jit.js I found something which looks like a bug. Below is the hide function which basically sets style.display to 'none'.

  hide: function(triggerCallback) {
    this.tip.style.display = 'none';
    triggerCallback && this.config.onHide();
  }

Now look at the code below.

  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';
  }

As you can see the onShow function is called from the onMouseMove function. And after onShow, setTooltipPosition function is called which sets the style.display back to ' ' (see my comment in code). Because of this the tip is not being hidden even after calling hide() from onShow function. When I commented out that line in setTooltipPosition, it worked i.e. tool tips were hidden for nodes which were hidden.

Is this a bug in infovis or am I doing something wrong. I would like to know how is hide function supposed to be used if its not a bug.

Also, does anyone know of any other better way to hide a tool tip?

Pratik Patel
  • 1,305
  • 1
  • 17
  • 44

1 Answers1

0

I had a similar problem. The solution was to use the .css('visibility', 'visible') instead of .hide() - because the element was hidden to start with using css styling.

Mike Weber
  • 311
  • 2
  • 16