javascriptjqueryd3.jstooltiptipsy

Creating tooltip on maps using d3.js


I am expanding this example http://bl.ocks.org/tommyskg/6111032

I am working to add tooltip to point whenever I click on it: I use d3.JS
http://onehackoranother.com/projects/jquery/tipsy/#download

      // Add a circle.
      marker.append("svg:circle")
                        .attr("r", 4.5)
                        .attr("cx", padding)
                        .attr("cy", padding)
                        .on("click",info)


     function info(){
        d3.select(this).tipsy({live: true});
      };

But I am getting this error: Uncaught TypeError: Object [object Array] has no method 'tipsy'

It seems that I am using JQuery two times

How canI cut this conflict ?

Second way :

I though that there is problems with map as the tooltip could be hiding behind map. I made position of tooltip when it displays relative. I coded that manually.

div.tooltip {
  color: #222; 
  background: #fff; 
  padding: .5em; 
  text-shadow: #f5f5f5 0 1px 0;
  border-radius: 2px; 
  box-shadow: 0px 0px 2px 0px #a6a6a6; 
  opacity: 0.9; 
  position: relative;
}

var tooltip = d3.select("#map").append("div")

  function info(){
            tooltip.attr("class", "tooltip");
          };

     marker.append("svg:circle")
                            .attr("r", 4.5)
                            .attr("cx", padding)
                            .attr("cy", padding)
                            .on("click",info)

But I couldn't reach results ? Any ideas to solve this issue ?


Solution

  • Problem one

    tipsy is a jQuery plugin, so you need to wrap the DOM element as a jQuery object (not a d3 selection) to get access to the tipsy function:

    function info () { $(this).tipsy({live: true}); }
    

    Problem two

    I suspect that you are appending a div to a svg element. That is not allowed.

    Also, I think the tooltips should show up just fine: http://bl.ocks.org/ilyabo/1373263