I have a figure created with D3 that has tooltips that appear near a data point when I over it and that I can pin by clicking on that point. I also have the ability to change what values are plotted for the points by clicking on some text to change the "view" of the figure, and would like a pinned tooltip to follow the data point as it is repositioned, but I can't figure out how to do that. Specifically, I have two problems the following problem:
(1) I don't know how to go from the selected point to the coordinates I need to position the tooltip absolutely in the body
of my page.
I've tried
tooltip.transition().duration(1000)
.style("left", d3.select(".dot-selected").attr("cx") + 5 + "px")
.style("top", d3.select(".dot-selected").attr("cy") - 5 + "px");
where the class "dot-selected" is present only for the selected point (a fact which I can confirm because its appearance changes), but this only results in approximately correct positioning.
(2) The tooltip's position (approximate or otherwise) seems to lag view changes. That is, when I change the view and move a data point, the tooltip seems to position where the point was, not where it is. I call the code above at the very end of a view update, so everything else should have updated, in particular, new values for "cx" and "cy" should have been assigned earlier.