diff --git a/lib/forcegraph.js b/lib/forcegraph.js index 7f80827..1c3b9da 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -469,6 +469,21 @@ define(["d3"], function (d3) { } } + function keyboardZoom(z) { + return function () { + var e = d3.event + + if (e.altKey || e.ctrlKey || e.metaKey) + return + + if (e.keyCode === 43) + animatePanzoom(z.translate(), z.scale() * 1.41) + + if (e.keyCode === 45) + animatePanzoom(z.translate(), z.scale() / 1.41) + } + } + el = document.createElement("div") el.classList.add("graph") self.div = el @@ -479,10 +494,11 @@ define(["d3"], function (d3) { .translate([sidebar.getWidth(), 0]) canvas = d3.select(el) - .call(zoomBehavior) .append("canvas") - .attr("pointer-events", "all") + .attr("tabindex", 1) .on("click", onClick) + .on("keypress", keyboardZoom(zoomBehavior)) + .call(zoomBehavior) .call(draggableNode) .node()