@ -1099,17 +1099,17 @@ Now when you zoom out, the axes should redraw themselves:
Try zoom/panning and the 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/pan has happened. Currently, if you click on the visual point, no matter how much you may have zoomed/panned, the click handler still converts it as if you had never zoomed/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;` at the beginning of the function declaration. It should look like this:
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 `let lastTransform = null` right before it. Then add `lastTransform = event.transform;` at the beginning of the function declaration. It should look like this:
@ -1157,23 +1157,23 @@ But now clicking before any zoom is broken, since `lastTransform` will be null:
Find the code that we just wrote for the SVG click handler:
```javascript
var x = lastTransform.invertX(d3.event.offsetX);
var y = lastTransform.invertY(d3.event.offsetY);
const x = lastTransform.invertX(event.offsetX);
const y = lastTransform.invertY(event.offsetY);
```
And adjust it so it looks like this:
```javascript
var x = d3.event.offsetX;
var y = d3.event.offsetY;
let x = event.offsetX;
let y = event.offsetY;
if(lastTransform !== null){
x = lastTransform.invertX(d3.event.offsetX);
y = lastTransform.invertY(d3.event.offsetY);
x = lastTransform.invertX(event.offsetX);
y = lastTransform.invertY(event.offsetY);
}
```
Now initially, `x` and `y` are set to `d3.event.offsetX` and `d3.event.offsetY`, respectively. If a zoom/pan occurs, `lastTransform` will not be null, so we overwrite `x` and `y` with the transformed values.
Now initially, `x` and `y` are set to `event.offsetX` and `event.offsetY`, respectively. If a zoom/pan occurs, `lastTransform` will not be null, so we overwrite `x` and `y` with the transformed values.