Created
April 29, 2014 23:51
-
-
Save greglockwood/02a230d6561f94d48fea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
svg.on("mousemove", function() { | |
var x = d3.event.pageX - offsetLeft; | |
var beginning = x, end = pathLength, target; | |
while (true) { | |
target = Math.floor((beginning + end) / 2); | |
pos = pathEl.getPointAtLength(target); | |
pos.x += margin.left; | |
pos.y += margin.top; | |
if ((target === end || target === beginning) && pos.x !== x) { | |
break; | |
} | |
if (pos.x > x) end = target; | |
else if (pos.x < x) beginning = target; | |
else break; //position found | |
} | |
if (pos.x >= xScale.range()[0] && pos.x <= xScale.range()[1] + margin.left) { | |
var date = xScale.invert(pos.x); | |
circle | |
.attr("opacity", 1) | |
.attr("cx", pos.x) | |
.attr("cy", pos.y); | |
tooltip.transition() | |
.duration(200) | |
.style("opacity", .9); | |
tooltip .html(formatTime(date) + "<br/>" + getValueAt(date, data)) | |
.style("left", d3.event.pageX + "px") | |
.style("top", (d3.event.pageY - 28) + "px"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment