mbostock/d3 — pull request #2022 by jchlapinski (2014-09-17 11:54:24+00:00)
Title: Zoom behavior with custom scaling

I have added support for custom scaling while zooming with `d3.behavior.zoom`. Example and changes in d3 API are described at http://bl.ocks.org/jchlapinski/d51d9aca2084bc02f30b

A method `scaleGenerator` was added to the 'zoom' object as follows:
```javascript
var zoom = d3.behavior.zoom();

zoom.scaleGenerator(function (scale, delta, usecase) { // below is the default implementation
if (usecase === "mousewheel") {
// delta = event.deltaY (or equivalent for different browsers);
return Math.pow(2, delta * .002) * k;
} else if (usecase === "dbltap") {
// delta = 0
return k * 2;
} else if (usecase === "dblclick") {
// delta = 1 or -1 if user double-clicks while holding SHIFT
return Math.pow(2, delta < 0 ? Math.ceil(Math.log(k) / Math.LN2) - 1 : Math.floor(Math.log(k) / Math.LN2) + 1);
} else if (usecase === "touchzoom") {
// delta is equal to the distance change between touches (two-finger) in pixels
return k * delta;
}
return k;
});

var sg = zoom.scaleGenerator(); // get current scale generator

zoom.scaleGenerator(null); // restore default scale generator
```