1

Hello I wanted to get the position of a node or text of d3js to submit a popup from its position, thanks. I have this:

                                nodeEnter.append("a")
                                        .attr("xlink:href", function (d) {
                                            return d.path;
                                        })
                                        .style("text-decoration", "none")
                                        .style("display", function (d) {
                                           return (d.name == node_info.name && d.not_beneficially_held == "true") ? "block" : "none";
                                        })                                
                                        .append("text")
                                        .attr("x", function (d) {
                                            return (d == root) ? 17 : 15;
                                        })
                                        .attr("y", function (d) {
                                            return (d == root) ? 21 : 25;
                                        })
                                        .attr("text-anchor", function (d) {
                                            return d.children || d._children ? "end" : "start";
                                        })
                                        .text(function (d) {
                                            return "$";
                                        })
                                        .style("fill", function (d) {
                                            return "#4682b4";
                                        })
                                        .on('click', function (d) {
                                            action_click = true;                                       
                                            $('#popup_paid').fadeIn('slow');
                                            $('.popup-overlay').fadeIn('slow');
                                            return false;
                                        })
                                        .on('mouseout', function (d) {
                                            d3.selectAll("a").remove();
                                        });

And this code or the offset jQuery not work for me:

                function getAbsoluteElementPosition(element) {
                  if (typeof element == "string")
                    element = document.getElementById(element)

                  if (!element) return { top:0,left:0 };                     

                  var y = 0;
                  var x = 0;
                  while (element.offsetParent) {
                    x += element.offsetLeft;
                    y += element.offsetTop;
                    element = element.offsetParent;
                  }
                  return {top:y,left:x};

var pos = getAbsoluteElementPosition(element);

When a normal HTML if I works perfectly.

Thanks in advance and greetings

Łukasz
  • 2,131
  • 1
  • 13
  • 28
Ingeweb es
  • 11
  • 2
  • Solution: http://stackoverflow.com/questions/16256454/d3-js-position-tooltips-using-element-position-not-mouse-position – Ingeweb es Jun 08 '15 at 06:39

0 Answers0