views:

306

answers:

2

I have a simplr svg-graph and I'm trying to create a simple tooltip-popup for this graph, but I'm unable to find out how to set the position of the tooltip properly.

I have a .css where my popup-div is absolute:

#popup {
    position: relative

When creating nodes in the svg I hook a listener like:

    p.setAttributeNS(null,"onmousemove","parent.drawPopup(evt)");

Now to my problem, in the drawPopup callack, I cannot figure out how to set the coordinates correctly, I've tried something like the following in the drawPopu function:

pop = document.getElementById("popup"); 
pop.innerHTML = popupText;
pop.style.visibility='visible';
pop.style.left=evt.pageX + 'px';

but the pageX seem to be relative to the svg.graph, so I need to offset it somehow?

How does one usually do with problems like this? Any suggestions?

+2  A: 

You might want to position the tooltip absolutely, your CSS rule states relative, and use the mouse x,y coordinates to place it on top of the graph since the tooltip is triggered by the mouse pointer anyways.

This link to quirksmode.org will have some helpful info, scroll down the page or search for mouse position and you'll find some tips on accurately calculating mouse x,y coordinates.

Mike Mytkowski
A: 

Take a look at Raphael.

http://raphaeljs.com/

Excellent vector javascript library.

LinuxGnut
You could have at least explained how he could do it with Raphael, instead of just promoting it.
Bob
Agreed. Actually, I just found this post because I'm looking for a way to do popups with Raphael....and there's no easy way to do so!
mlissner