Updating click points after a transform

Try zooming and panning and then clicking on the SVG to create a new run. You'll notice it's in the wrong place. That's because the SVG click handler has no idea that a zoom or pan has happened. Currently, if you click on the visual point, no matter how much you may have zoomed or panned, the click handler still converts it as if you had never zoomed or panned.

When we zoom, we need to save the transformation information to a variable so that we can use it later to figure out how to properly create circles and runs. Find the zoomCallback declaration and add var lastTransform = null right before it. Then add lastTransform = d3.event.transform; to the beginning of the function declaration. It should look ...

Get D3.js Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.