@ -833,10 +833,13 @@ When you drag the circle, it should turn red
## Create a zoom behavior that scales elements
## Create a zoom behavior that scales elements
- Another behavior we can create is the zooming ability
- Another behavior we can create is the zooming/panning ability. To do this you can do any of the following:
- two finger drag
- zoom:
- mouse wheel
- two finger drag on a trackpad
- pinch/spread
- rotate your mouse wheel
- pinch/spread on a trackpad
- pan:
- click/drag the svg element
```javascript
```javascript
//put this at the end of app.js
//put this at the end of app.js
@ -848,9 +851,11 @@ var zoom = d3.zoom() //create the zoom behavior
d3.select('svg').call(zoom); //attach the behavior to the svg element
d3.select('svg').call(zoom); //attach the behavior to the svg element
```
```
## Update axes when zooming
![]()
## Update axes when zooming/panning
To update the axes, let's first add ids to the `<g>` elements that contain them
Now when we zoom, the points move in/out. When we pan, they move vertically/horizontally. Unfortunately, the axes don't update accordingly. Let's first add ids to the `<g>` elements that contain them
```javascript
```javascript
d3.select('svg')
d3.select('svg')
@ -871,14 +876,16 @@ Now let's use those ids when we zoom:
d3.select('#x-axis').call(bottomAxis.scale(d3.event.transform.rescaleX(xScale))); //tell the bottom axis to adjust its values based on how much we zoomed