forcegraph: fix translation of keyboard zoom

This commit is contained in:
Nils Schneider 2015-07-08 15:17:09 +02:00
parent 189172ac65
commit 301630e47e

View file

@ -469,6 +469,18 @@ define(["d3"], function (d3) {
} }
} }
function zoom(z, scale) {
var size = getSize()
var newSize = [size[0] / scale, size[1] / scale]
var sidebarWidth = sidebar.getWidth()
var delta = [size[0] - newSize[0], size[1] - newSize[1]]
var translate = z.translate()
var translateNew = [sidebarWidth + (translate[0] - sidebarWidth - delta[0] / 2) * scale, (translate[1] - delta[1] / 2) * scale]
animatePanzoom(translateNew, z.scale() * scale)
}
function keyboardZoom(z) { function keyboardZoom(z) {
return function () { return function () {
var e = d3.event var e = d3.event
@ -477,10 +489,10 @@ define(["d3"], function (d3) {
return return
if (e.keyCode === 43) if (e.keyCode === 43)
animatePanzoom(z.translate(), z.scale() * 1.41) zoom(z, 1.41)
if (e.keyCode === 45) if (e.keyCode === 45)
animatePanzoom(z.translate(), z.scale() / 1.41) zoom(z, 1 / 1.41)
} }
} }