|
|
|
|
@ -241,16 +241,17 @@ You can use the xScale.invert and yScale.invert to get data from d3.event.x and
|
|
|
|
|
### Zooming
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
//generator for a behavior
|
|
|
|
|
//scale from 1 - 10
|
|
|
|
|
//.on function says, when there's an event of type 'zoom', call the 'zoomed' function. Could be any event
|
|
|
|
|
var zoom = d3.behavior.zoom().scaleExtent([1,10]).on('zoom', zoomed);
|
|
|
|
|
var svg = d3.select('#viz-wrapper').append('svg').call(zoom);
|
|
|
|
|
function zoomed(){
|
|
|
|
|
console.log(d3.event.translate);//get mouse position
|
|
|
|
|
console.log(d3.event.scale);//bounded by 1,10 as set up above
|
|
|
|
|
viz.attr('transform', 'translate(' + d3.event.translate + ')' + 'scale(' + d3.event.scale + ')');
|
|
|
|
|
//previously defined: var xAxis = d3.axisBottom(xScale);
|
|
|
|
|
//previously defined: var yAxis = d3.axisLeft(yScale);
|
|
|
|
|
//previously defined: d3.select('svg').append('g').attr('id', 'x-axis').attr('transform', 'translate(0,' + HEIGHT + ')').call(xAxis);
|
|
|
|
|
//previously defined: d3.select('svg').append('g').attr('id', 'y-axis').call(yAxis); //y axis is good as it is
|
|
|
|
|
var zoomCallback = function(){
|
|
|
|
|
d3.select('#points').attr("transform", d3.event.transform);
|
|
|
|
|
d3.select('#x-axis').call(xAxis.scale(d3.event.transform.rescaleX(xScale)));
|
|
|
|
|
d3.select('#y-axis').call(yAxis.scale(d3.event.transform.rescaleY(yScale)));
|
|
|
|
|
}
|
|
|
|
|
var zoom = d3.zoom().on('zoom', zoomCallback);
|
|
|
|
|
d3.select('svg').call(zoom);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Basic Layouts
|
|
|
|
|
|