From 301630e47eedac9d7f22dc6260134060f432bc47 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Wed, 8 Jul 2015 15:17:09 +0200 Subject: [PATCH] forcegraph: fix translation of keyboard zoom --- lib/forcegraph.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/forcegraph.js b/lib/forcegraph.js index 5b350a0..3d06055 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -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) { return function () { var e = d3.event @@ -477,10 +489,10 @@ define(["d3"], function (d3) { return if (e.keyCode === 43) - animatePanzoom(z.translate(), z.scale() * 1.41) + zoom(z, 1.41) if (e.keyCode === 45) - animatePanzoom(z.translate(), z.scale() / 1.41) + zoom(z, 1 / 1.41) } }